Dan Shultz • OverDrive, Inc
@danshultz
...that makes it easy to deploy servers and applications to any physical, virtual or cloud location, no matter the size of the infrastructure.
Recipe runs of the same configuration always produce the same resolution across systems and chef runs where nothing has changed, take no actions
Chef order is declarative and recipes are run in the order they are declared. Within a recipe, resources are applied in the order they are declared. There is no dependency management system. If you add a new cookbook/recipe at the end of your run list, the run order doesn't change
Generic Cookbooks work with little or no configuration. Attributes are easily changed and assigned
% tree cookbooks/mycookbook
cookbooks/mycookbook
├── README.md
├── attributes
├── definitions
├── files
│ └── default
├── libraries
├── metadata.rb
├── providers
├── recipes
│ └── default.rb
├── resources
└── templates
└── default
Scripts to install/configure servers and define services
package node['nginx']['package_name']
template "nginx.conf" do
path "#{node['nginx']['dir']}/nginx.conf"
source "nginx.conf.erb"
owner "root"
group "root"
mode 00644
notifies :reload, 'service[nginx]'
end
service 'nginx' do
supports :status => true, :restart => true, :reload => true
action :enable
end
Configuration for recipes
default['nginx']['version'] = "1.2.6"
default['nginx']['package_name'] = "nginx"
default['nginx']['dir'] = "/etc/nginx"
default['nginx']['log_dir'] = "/var/log/nginx"
default['nginx']['binary'] = "/usr/sbin/nginx"
Development environments made easy.
$ cap chef deploy:setup
% tree rails_app/
rails_app/
├── attributes
├── definitions
├── libraries
├── metadata.rb
├── providers
├── recipes
│ ├── app.rb
│ ├── database.rb
│ ├── default.rb
│ └── web.rb
├── resources
└── templates
└── default
└── pg_hba.conf.erb
include_recipe("postgresql")
include_recipe("postgresql::server")
include_recipe("postgresql::ruby")
# use a custom hba_config
hba_conf = resources("template[#{node['postgresql']['dir']}/pg_hba.conf]")
hba_conf.source("pg_hba.conf.erb")
hba_conf.cookbook("rails_app")
postgresql_connection_info = {
:host => "localhost",
:port => node['postgresql']['config']['port'],
:username => 'postgres',
:password => node['postgresql']['password']['postgres']
}
rails_app/recipes/database.rb
$ berks cookbook rails_app
Berksfile
site :opscode
cookbook('nginx', '~> 1.7.0')
cookbook('postgresql', '~> 3.0.2')
cookbook('ssh-keys')
cookbook('rails_app', :path => './chef/cookbooks/rails_app')
set(:chef_attributes) { File.join('/etc/chef', "attributes.json") }
find_servers.each { |server|
json = JSON.pretty_generate(server.options[:chef_attributes])
put(json, chef_attributes, :hosts => server.host)
}
sudo("chef-solo -j #{chef_attributes}")
$ cap chef deploy
Dan Shultz • OverDrive, Inc
@danshultz