Skip to content

Instantly share code, notes, and snippets.

@cliffdickerson
cliffdickerson / gist:624320
Created October 13, 2010 15:55 — forked from jellybob/gist:624309
using chef in cap
require 'chef/config'
require 'chef/node'
Chef::Config.from_file(File.join("etc", "chef", "client.rb"))
node = Chef::Node.load("node_name")
require 'chef/data_bag'; require 'chef/data_bag_item'; Chef::DataBagItem.load(databag, id);
@cliffdickerson
cliffdickerson / gist:282007
Created January 20, 2010 17:07
chef client requirments
abstract (1.0.0)
amqp (0.6.5)
chef (0.8.0)
deep_merge (0.1.0)
erubis (2.6.5)
eventmachine (0.12.10)
extlib (0.9.13)
json (1.1.9)
mixlib-authentication (1.0.0)
mixlib-cli (1.0.4)
@cliffdickerson
cliffdickerson / shef.rb
Created January 20, 2010 17:03 — forked from danielsdeleo/shef.rb
Shef - chef in irb
$ bin/shef
Loading Node Data
Ohai2u!
chef > recipe
=> :recipe
chef:recipe > file "/tmp/foo"
=> #<Chef::Resource::File:0x1c3cd2c @provider=nil, @not_if=nil, @params={}, @recipe_name=nil, @action="create", @source_line="/Users/danielsdeleo/ruby/shef/(irb) line 2", @actions={}, @ignore_failure=false, @name="/tmp/foo", @cookbook_name=nil, @enclosing_provider=nil, @resource_name=:file, @before=nil, @supports={}, @backup=5, @allowed_actions=[:nothing, :create, :delete, :touch, :create_if_missing], @path="/tmp/foo", @only_if=nil, @noop=nil, @updated=false, @node=eigenstate.local, @collection=#<Chef::ResourceCollection:0x1c4f328 @insert_after_idx=nil, @resources=[#<Chef::Resource::File:0x1c3cd2c ...>], @resources_by_name={"file[/tmp/foo]"=>0}>>
chef:recipe > run_chef
[Tue, 03 Nov 2009 22:16:27 -0700] DEBUG: Processing file[/tmp/foo]
[Tue, 03 Nov 2009 22:16:27 -0700] DEBUG: file[/tmp/foo] using Chef::Provider::File
@cliffdickerson
cliffdickerson / build_chef_0.8
Created January 20, 2010 02:00 — forked from jasherai/build_chef_0.8
Chef .8 on ec2
# ec2 ami-1515f67c
sudo sed -i 's/universe/multiverse universe/' /etc/apt/sources.list
sudo apt-get update
sudo apt-get install -y ruby ruby1.8-dev libopenssl-ruby1.8 rdoc ri irb build-essential wget ssl-cert rubygems git-core rake librspec-ruby libxml-ruby thin couchdb
sudo gem sources -a http://gems.opscode.com
sudo gem sources -a http://gemcutter.org # for nanite
sudo gem install cucumber merb-core nanite jeweler uuidtools json --no-ri --no-rdoc
mkdir ~/src
cd ~/src
git clone git://github.com/opscode/chef.git
@cliffdickerson
cliffdickerson / build_chef_0.8
Created January 20, 2010 02:00 — forked from btm/build_chef_0.8
Chef .8 on ubuntu
# ec2 ami-1515f67c
sudo sed -i 's/universe/multiverse universe/' /etc/apt/sources.list
sudo apt-get update
sudo apt-get install -y ruby ruby1.8-dev libopenssl-ruby1.8 rdoc ri irb build-essential wget ssl-cert rubygems git-core rake librspec-ruby libxml-ruby thin couchdb zlib1g-dev libxml2-dev
sudo gem sources -a http://gems.opscode.com
sudo gem install cucumber merb-core jeweler uuidtools json libxml-ruby --no-ri --no-rdoc
mkdir ~/src
cd ~/src
git clone git://github.com/opscode/chef.git
git clone git://github.com/opscode/ohai.git
$ bin/shef
Loading Node Data
Ohai2u!
chef > recipe
=> :recipe
chef:recipe > file "/tmp/foo"
=> #<Chef::Resource::File:0x1c3cd2c @provider=nil, @not_if=nil, @params={}, @recipe_name=nil, @action="create", @source_line="/Users/danielsdeleo/ruby/shef/(irb) line 2", @actions={}, @ignore_failure=false, @name="/tmp/foo", @cookbook_name=nil, @enclosing_provider=nil, @resource_name=:file, @before=nil, @supports={}, @backup=5, @allowed_actions=[:nothing, :create, :delete, :touch, :create_if_missing], @path="/tmp/foo", @only_if=nil, @noop=nil, @updated=false, @node=eigenstate.local, @collection=#<Chef::ResourceCollection:0x1c4f328 @insert_after_idx=nil, @resources=[#<Chef::Resource::File:0x1c3cd2c ...>], @resources_by_name={"file[/tmp/foo]"=>0}>>
chef:recipe > run_chef
[Tue, 03 Nov 2009 22:16:27 -0700] DEBUG: Processing file[/tmp/foo]
[Tue, 03 Nov 2009 22:16:27 -0700] DEBUG: file[/tmp/foo] using Chef::Provider::File
ips = {}
ips[:internal] = node[:ipaddress]
eth = node[:network][:interfaces][:eth1][:addresses]
eth.each_key do |i|
if eth[i][:family] == "inet"
ips[:external] = i
end
end
fqdns = Array.new
search(:node) do
with :fqdn, '*opscode.com'
with(:uptime).less_than Time.now
order_by :updtime, :desc
result do |n|
fqdns << n.fqdn
end
end
@cliffdickerson
cliffdickerson / default.rb
Created July 9, 2009 03:55 — forked from btm/default.rb
cookbook info in a templated file
template "/tmp/foo" do
source "foo.erb"
variables({
:recipe_name => self.recipe_name,
:cookbook_name => self.cookbook_name
})
end
%w{
package1
package2
package3
package4
}.each do |name|
package name do
action :install
end
end