Skip to content

Instantly share code, notes, and snippets.

@btm
btm / gist:5759302
Created June 11, 2013 18:12
portsnap update
if File.exists?("/usr/ports")
execute "Update Ports Tree" do
command <<-EOS
sed -e 's/\\[ ! -t 0 \\]/false/' /usr/sbin/portsnap > /tmp/portsnap
chmod +x /tmp/portsnap
/tmp/portsnap update
EOS
end
else
execute "Create Ports Tree" do
@btm
btm / ec2_fetchkey
Created May 30, 2013 22:46
FreeBSD + Openstack Notes
#!/bin/sh
# PROVIDE: ec2_fetchkey
# REQUIRE: NETWORKING
# BEFORE: LOGIN ec2_firstboot
# Define ec2_fetchkey_enable=YES in /etc/rc.conf and create /root/firstboot
# to enable SSH key fetching when the system next boots.
#
: ${ec2_fetchkey_enable=NO}
#
# Author:: Adam Jacob (<[email protected]>)
# Author:: John Keiser (<[email protected]>)
# Copyright:: Copyright (c) 2012 Opscode, Inc.
# License:: Apache License, Version 2.0
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
@btm
btm / gist:5086184
Last active December 14, 2015 12:28 — forked from maplebed/gist:5086156
# If the host has ganglia in the run_list, install the mongo plugin
# In Chef 11 node.recipe? returns true for the run_list and expanded_runlist (node[:recipes])
# In Chef 10 node.recipe? returns true for the run_list and already loaded recipes (seen_recipes)
# -- I believe on Chef 10 node.recipe? does not evaluated the expanded run_list so you want node[:recipes] too
if node.recipe?("ganglia::default") or node[:recipes].include?("ganglia::default")
# Make sure we've already executed the ganglia recipe in this run to get the ganglia_python LWRP
include_recipe "ganglia::default"
ganglia_python "mongodb" do
action :enable
end
@btm
btm / gist:4997453
Created February 20, 2013 17:47
Downloading a chef cookbook from a git repository
# Downloading a chef cookbook from a git repository
btm@btm-mbp-dev:~/devel/chef-repo/cookbooks [master] $ wget https://github.com/opscode-cookbooks/apache2/archive/master.zip
[snip]
2013-02-20 09:43:44 (349 KB/s) - `master.zip' saved [142580/142580]
btm@btm-mbp-dev:~/devel/chef-repo/cookbooks [master] $ unzip master.zip
Archive: master.zip
[snip]
btm@btm-mbp-dev:~/devel/chef-repo/cookbooks [master] $ mv apache2-master apache2
btm@btm-mbp-dev:~/devel/chef-repo/cookbooks [master] $ knife cookbook upload apache2
$ gem list ohai
*** LOCAL GEMS ***
ohai (6.14.1, 6.14.0, 6.14.0.rc.1, 0.6.12)
$ cat /tmp/test.rb
chef_gem "ohai" do
version ">= 6.16.0"
end
$ sudo chef-apply /tmp/test.rb
@btm
btm / gist:4382499
Last active December 10, 2015 04:38
# Accessing dmi information in the chef-shell
# must use 'sudo shef' or 'sudo chef-shell' for dmidecode
chef > if node[:dmi] && node[:dmi][:system] && node[:dmi][:system][:manufacturer] =~ /VMware/
chef ?> puts "On a VMWare Guest"
chef ?> end
On a VMWare Guest
=> nil
chef > node.automatic[:dmi] = nil
=> nil
@btm
btm / gist:4073447
Created November 14, 2012 17:19 — forked from anonymous/gist:3984352
def configure_session
list = case config[:manual]
when true
@name_args[0].split(" ")
when false
r = Array.new
q = Chef::Search::Query.new
@action_nodes = q.search(:node, @name_args[0])[0]
@action_nodes.each do |item|
# we should skip the loop to next iteration if the item returned by the search is nil
@btm
btm / load_expanded_node.rb
Created September 28, 2012 01:24
script for loading a node from json, expanding the run list and saving.
#!/usr/bin/env ruby
# Copyright 2012 Opscode <[email protected]>
#
# Licensed to the Apache Software Foundation (ASF) under one
# or more contributor license agreements. See the NOTICE file
# distributed with this work for additional information
# regarding copyright ownership. The ASF licenses this file
# to you under the Apache License, Version 2.0 (the
# "License"); you may not use this file except in compliance
# with the License. You may obtain a copy of the License at
#!/usr/bin/env ruby
# Copyright 2012 Opscode <[email protected]>
#
# Licensed to the Apache Software Foundation (ASF) under one
# or more contributor license agreements. See the NOTICE file
# distributed with this work for additional information
# regarding copyright ownership. The ASF licenses this file
# to you under the Apache License, Version 2.0 (the
# "License"); you may not use this file except in compliance
# with the License. You may obtain a copy of the License at