7. "Chef is an open source systems integration framework built
to bring the benefits of configuration management to your
entire infrastructure."
"You write source code to describe how you want each part of
your infrastructure to be built, then apply those descriptions
to your servers."
"The result is a fully automated infrastructure: when a new
server comes on line, the only thing you have to do is tell Chef
what role it should play in your architecture."
47. # cookbooks/repos/recipes/default.rb
case node[:platform]
when 'fedora'
path = "/tmp/rpmfusion-free-release-stable.noarch.rpm"
bash "download rpmfusion free package" do
code "wget http://download1.rpmfusion.org/.../" +
"rpmfusion-free-release-stable.noarch.rpm -O #{path}"
not_if { File.exist?(path) }
end
package "rpmfusion-free-release-stable" do
source path
options "--nogpgcheck"
end
when 'ubuntu'
...
end
48. end
# cookbooks/repos/recipes/default.rb
case node[:platform]
when 'fedora'
...
when 'ubuntu'
bash "enable multiverse repo" do
code "head -n 1 /etc/apt/sources.list | " +
"sed 's/main universe/multiverse/' " +
">> /etc/apt/sources.list"
not_if "egrep '^deb.+multiverse' /etc/apt/sources.list"
end
end
52. # cookbooks/skype/recipes/default.rb
case node[:platform]
when 'ubuntu'
include_recipe 'init::ubuntu' # for partner repo
package 'skype'
when 'mac_os_x'
dmg_package "Skype" do
source "http://www.skype.com/go/getskype-macosx.dmg"
action :install
end
when 'fedora'
...
end
56. Each server we configure has its corresponding node
configuration file in nodes/ directory of kitchen project that
specifies run_list and few other settings
62. set :user, 'chef'
NODE_LIST = Dir["nodes/*.json"].map do |nodefile|
File.basename(nodefile, '.json')
end
NODE_LIST.each do |node|
role node.to_sym, node
end
NODE_CONFIG = <<-EOS
file_cache_path '/tmp/chef-solo'
cookbook_path '/tmp/chef-solo/cookbooks'
role_path '/tmp/chef-solo/roles'
EOS
...
63. ...
namespace :configure do
NODE_LIST.each do |node|
desc "Configure #{node}"
task node.to_sym, :roles => node.to_sym do
run "if [ ! -e /tmp/chef-solo ]; then mkdir /tmp/chef-sol
upload("cookbooks", "/tmp/chef-solo/", :via => :scp, :rec
upload("roles", "/tmp/chef-solo/", :via => :scp, :recursi
upload("nodes/#{node}.json", "/tmp/chef-solo/node.json",
put(NODE_CONFIG, "/tmp/chef-solo/solo.rb")
run "rvmsudo chef-solo " +
"-c /tmp/chef-solo/solo.rb " +
"-j /tmp/chef-solo/node.json"
end
end
end