An introduction to Chef with the simplest Chef that could possibly work.
cooking infrastructurewith chefruby for scotland 2013, mathias meyer, @roidrage
View Slide
travis-ci.org
in the beginning...
manual steps
useradd -h /var/www deploy
apt-get install nginxvi /etc/nginx/nginx.confmkdir /var/www/travis-ci.orgcp ~/ssl.cert /etc/nginx/service nginx reload
apt-get install mysql-servervi /etc/mysql/my.cnfservice mysql-server restartmkdir /var/www/travis-ci.org/sharedvi /var/www/travis-ci.org/shared/database.yml
cp /tmp/id_rsa ~/.ssh/id_rsachmod 600 ~/.ssh/id_rsagit clone [email protected]:travis-ci/travis-ci.git
artisanal shell scripts
every installationhowto ever
infrastructure grows
infrastructurechanges
teams grow andchange
automation
chef
chef lingo
borknodesattributesresourcesprovidersrecipescookbooks
nodes
attributes
default[:nginx][:version] = '1.1.19-1'default[:users] = [{id: 1001,username: 'deploy',home: '/var/www',shell: '/bin/zsh'}]
resources
package "nginx" doversion "1.1.19-1"action :installend
package "nginx" doversion node[:nginx][:version]action :installend
user 'deploy' doid 1001shell '/bin/zsh'home '/var/www'end
default[:users] = [{id: 1001,username: 'deploy',home: '/var/www',shell: '/bin/zsh'}]
node[:users].each do |user|user user[:login] douid user[:id]shell user[:shell]home user[:home]endend
it's all ruby
providers
directories
directory node[:nginx][:www_root] doaction :createrecursive trueend
configuration files
template "/etc/nginx/sites-available/travis-ci.org" dosource "travis-ci.org.erb"owner "www-data"group "www-data"mode "0644"end
default[:nginx][:sites_available] ='/etc/nginx/sites-available'default[:nginx][:sites_enabled] ='/etc/nginx/sites-enabled'default[:nginx][:site_config] ="#{node[:nginx][:sites_available]}/" +"#{node[:nginx][:host_name]}"
template node[:nginx][:site_config] dosource "travis-ci.org.erb"owner "www-data"group "www-data"mode "0644"end
services
service "nginx" dosupports reload: true, restart: trueaction :startend
template node[:nginx][:site_config] dosource "travis-ci.org.erb"owner "www-data"group "www-data"mode "0644"notifies :reload, 'service[nginx]'end
customizingtemplates
server {listen 80;server_name <%= @host_name %>;root <%= @www_root %>;location / {index index.html}}
template "/etc/nginx/sites-available/travis-ci.org" dosource "travis-ci.org.erb"notifies :reload, 'service[nginx]'variables www_root: node[:nginx][:www_root],host_name: node[:nginx][:host_name]end
default[:nginx][:www_root] = '/var/www/travis-ci.org'default[:nginx][:host_name] = 'travis-ci.org'
link "#{node[:nginx][:sites_enabled]}/" +node[:nginx][:host_name] doto node[:nginx][:sites_config]owner "www-data"group "www-data"end
recipes
package "nginx" do...endtemplate "/etc/nginx/sites-available/travis-ci.org" do...endservice "nginx" do...end
cookbooks
simplest chef that could possibly work
chef mantras
order of execution
idempodence
chef is hard
infrastructure is hard
infrastructureautomation
big upfront effort
plan to throw 1000servers away
quantifyable benefits?
how is this betterthan shell scripts?
common languagefor infrastructureautomation
mttns*mean time to new server
mttr
orchestration
chef solo
opsworks
chef server
chef server storescookbooksenvironmentsnodesdataroles
roleswwwrailsmysql-mastermysql-slave
environmentsstagingproductiontesting
automate yourservers
automate your laptop
learnchef.com
github.com/roidrage/scotrubyconf2013