Me?
Ken Robertson
Senior Software Engineer at Involver
Involver builds a social media marketing platform
Specialize in our platform’s reliability,
performance, and scalability
Our Chef Usage
10 separate environments
120+ servers
All managed with Chef
One Operations Engineer, Two Developers
What is Chef?
Server management and configuration in Ruby
Developed by OpsCode
Adopted by Engine Yard, 37signals, and more
Apache License
Chef isn’t alone
CFEngine: http://cfengine.com/
Puppet: http://www.puppetlabs.com/
http://en.wikipedia.org/wiki/
Comparison_of_open_source_configuration_man
agement_software
Why use Chef?
Repeatable system provisioning
Manual tweaks are not repeatable
Ease scaling
Avoid vendor lock-in
Definitions
for db in node[:mysql][:databases] do
mysql_database db[:name] do
root_user node[:mysql][:root_user] || 'root'
root_password node[:mysql][:root_password]
dbuser db[:user] || db[:name]
dbpassword db[:password]
end
end
Definitions
define :mysql_database do
execute "mysql-create-database" do
...
action :nothing
end
template "/tmp/mysql-#{params[:name]}.sql" do
source "create-database.sql.erb"
variables(:params => params)
notifies :run,
"execute[mysql-create-database]",
:immediately
end
end
Definitions
define :nginx_site do
include_recipe "nginx"
template "/etc/nginx/apps/#{params[:name]}.conf" do
source "#{params[:name]}.nginx.erb"
owner node[:user]
group node[:user]
mode 0644
variables(
:stage => params[:stage],
:name => params[:name]
)
notifies :reload, "service[nginx]", :delayed
end
end
Idempotency
execute "install-jruby" do
command %Q{
curl http://urlto/#{version}/jruby-src-#{version}.tar.gz -O &&
tar xvzf jruby-src-#{version}.tar.gz &&
pushd jruby-#{version} &&
ant &&
popd &&
mv jruby-#{version} /usr &&
rm jruby-src-#{version}.tar.gz &&
ln -snf /usr/jruby-#{version}/bin/jruby /usr/local/bin/jruby
}
creates "/usr/jruby-#{version}"
end
Idempotency - Fixed
execute "install-jruby" do
command %Q{
curl http://urlto/#{version}/jruby-src-#{version}.tar.gz -O &&
tar xvzf jruby-src-#{version}.tar.gz &&
pushd jruby-#{version} &&
ant &&
popd &&
mv jruby-#{version} /usr &&
rm jruby-src-#{version}.tar.gz
}
creates "/usr/jruby-#{version}/bin/jruby"
end
link "/usr/local/bin/jruby" do
to "/usr/jruby-#{version}/bin/jruby"
end