Kevin Smith is the Director of Server Engineering at Opscode and has been developing software for 17 years including 7 years with Erlang. He discusses infrastructure as code, configuration management with Chef, and how Chef can be used in large environments. Specifically, he covers how Chef uses recipes, roles, attributes and resources to declaratively configure nodes. He also discusses how the Chef server and clients interact and how search is used. Finally, he notes how Chef is open source and has a large community contributing cookbooks and tools to support deployments of all sizes.
2. Who am I?
• Director of Server Engineering @ Opscode
• Software developer for 17 years
• 7 years with Erlang
• Alumni of DCRI, SAS, Red Hat, Basho
• Erlang In Practice @ PragProg
3. Agenda
• Infrastructure as Code
• Configuration Management
• Chef 101
• Chef in Large Environments
http://www.flickr.com/photos/koalazymonkey/3590953001/
6. Enable the reconstruction
of the business from
nothing but a source code
repository, an application
data backup, and bare
metal resources.
Infrastructure as Code
12. This does not scale!
for i in `cat servers.txt` ; do scp ntp.conf root@$i:/etc/
ntpd.conf ; done
for i in `cat servers.txt` ; do ssh root@$i /etc/init.d/ntpd
restart ; done
for i in `cat servers.txt` ; do ssh root@$i chkconfig ntpd
on ; done
18. Idempotence
• Property of a
declarative interface
• f(x) = x
• Eliminates brittleness
• Safe to run over and
over
package "ntp" do
action :install
end
template "/etc/ntp.conf" do
source "ntp.conf.erb"
owner "root"
group "root"
mode 0644
notifies :restart, "service[ntpd]"
end
service "ntpd" do
action [:enable,:start]
end
19. Convergence
• Running an agent “converges”
a system onto desired state
• Fights entropy and
unauthorized changes
• Update function inputs to deal
with changing requirements
$ echo “boom” > /etc/ntp.conf
$ chef-client
$ grep server /etc/ntp.conf | head -n 1
us.pool.ntp.org
$ ps -e | grep ntp
1799 ? 00:00:00 ntpd
$ /etc/init.d/ntpd stop
$ chef-client
ps -e | grep ntp
1822 ? 00:00:00 ntpd
34. chef-client configures
resources on managed nodes.
cookbook_file
template
service
package
deploy
git
http_request
link
ruby_block
log
bash
execute
remote_file
user
35. Chef Resources
• Have a type.
• Have a name.
• Have parameters.
• Take action to put the resource
in the declared state.
• Can send notifications to other
resources.
package "apache2" do
action :install
end
template "/etc/apache2/apache2.conf" do
source "apache2.conf.erb"
owner "root"
group "root"
mode 0644
notifies :restart, "service[apache2]"
end
service "apache2" do
supports :restart => true
action [:enable, :start]
end
38. Chef Recipes
• Resources are evaluated in the
order they appear.
package "haproxy" do
action :install
end
template "/etc/haproxy/haproxy.cfg" do
source "haproxy.cfg.erb"
owner "root"
group "root"
mode 0644
notifies :restart, "service[haproxy]"
end
service "haproxy" do
supports :restart => true
action [:enable, :start]
end
39. Chef Recipes
• Recipes can include other
recipes.
• Included recipes are also
evaluated in order.
include_recipe "apache2"
include_recipe "apache2::mod_rewrite"
include_recipe "apache2::mod_deflate"
include_recipe "apache2::mod_headers"
include_recipe "apache2::mod_php5"
40. Chef Recipes
• Extend recipes with
Ruby.
%w{ php5 php5-dev php5-cgi }.each do |pkg|
package pkg do
action :install
end
end
41. • Dynamic configuration
through search.
pool_members = search("node", "role:app_server")
template "/etc/haproxy/haproxy.cfg" do
source "haproxy.cfg.erb"
owner "root"
group "root"
mode 0644
variables :pool_members => pool_members
notifies :restart, "service[haproxy]"
end
Chef Recipes