running the show: configuration management with chef
DESCRIPTION
Few completed Rails apps are architecturally simple. As soon as you grow, you find yourself using multiple subsystems and machines to scale, creating new headaches in configuration management. Help is at hand! This tutorial introduces Chef, a modern Ruby-based open source approach to systems integration. Chef lets you manage your servers by writing code, not running commands.TRANSCRIPT
![Page 2: Running the Show: Configuration Management with Chef](https://reader034.vdocument.in/reader034/viewer/2022052618/55281a2b550346a4588b4623/html5/thumbnails/2.jpg)
About me
• Created Expectnation, event software that runs O’Reilly Conferences
• Co-author of “Learning Rails”
• Perennial tinkerer and author
2Monday, 4 May 2009
![Page 3: Running the Show: Configuration Management with Chef](https://reader034.vdocument.in/reader034/viewer/2022052618/55281a2b550346a4588b4623/html5/thumbnails/3.jpg)
Today’s tutorial
• Overview of Chef
• Learn by example
• Common usage patterns
• Moving on
3Monday, 4 May 2009
![Page 4: Running the Show: Configuration Management with Chef](https://reader034.vdocument.in/reader034/viewer/2022052618/55281a2b550346a4588b4623/html5/thumbnails/4.jpg)
Meta
• Please rate this talk and leavecomments
• If you’re twittering
• I’m @edd
• Hashtag is #railsconf
• Asking questions
4Monday, 4 May 2009
![Page 5: Running the Show: Configuration Management with Chef](https://reader034.vdocument.in/reader034/viewer/2022052618/55281a2b550346a4588b4623/html5/thumbnails/5.jpg)
About you
5Monday, 4 May 2009
![Page 6: Running the Show: Configuration Management with Chef](https://reader034.vdocument.in/reader034/viewer/2022052618/55281a2b550346a4588b4623/html5/thumbnails/6.jpg)
Overview
6Monday, 4 May 2009
![Page 7: Running the Show: Configuration Management with Chef](https://reader034.vdocument.in/reader034/viewer/2022052618/55281a2b550346a4588b4623/html5/thumbnails/7.jpg)
Configuration management
• Creating and maintaining consistency
• Installing, updating, reporting
• Rich history in open source tools
• cfengine through to Puppet
7Monday, 4 May 2009
![Page 8: Running the Show: Configuration Management with Chef](https://reader034.vdocument.in/reader034/viewer/2022052618/55281a2b550346a4588b4623/html5/thumbnails/8.jpg)
Today’s needs
• Developers are becoming ops people
• Web architectures and cloud computing
• Agile sysadmin should complement agile development
8Monday, 4 May 2009
![Page 9: Running the Show: Configuration Management with Chef](https://reader034.vdocument.in/reader034/viewer/2022052618/55281a2b550346a4588b4623/html5/thumbnails/9.jpg)
Developers want
• Don’t Repeat Yourself
• Revision control
9Monday, 4 May 2009
![Page 10: Running the Show: Configuration Management with Chef](https://reader034.vdocument.in/reader034/viewer/2022052618/55281a2b550346a4588b4623/html5/thumbnails/10.jpg)
Chef
• Client-server architecture
• Embraces modern web technologies
• Written in Ruby
10Monday, 4 May 2009
![Page 11: Running the Show: Configuration Management with Chef](https://reader034.vdocument.in/reader034/viewer/2022052618/55281a2b550346a4588b4623/html5/thumbnails/11.jpg)
Chef
• Cleeent-serfer ercheetectoore-a
• Imbreces mudern veb technulugeees
• Vreettee in Rooby
• Bork bork bork
11Monday, 4 May 2009
![Page 12: Running the Show: Configuration Management with Chef](https://reader034.vdocument.in/reader034/viewer/2022052618/55281a2b550346a4588b4623/html5/thumbnails/12.jpg)
Chef
• Has revision control at its core
• Doesn’t make you learn a new language
• Comes from a culture of testability and predictability
12Monday, 4 May 2009
![Page 13: Running the Show: Configuration Management with Chef](https://reader034.vdocument.in/reader034/viewer/2022052618/55281a2b550346a4588b4623/html5/thumbnails/13.jpg)
Chef vs Puppet
13Monday, 4 May 2009
![Page 14: Running the Show: Configuration Management with Chef](https://reader034.vdocument.in/reader034/viewer/2022052618/55281a2b550346a4588b4623/html5/thumbnails/14.jpg)
Chef vs Puppet
• Because we needed another open source war
• Objective differences
• Subjective differences
• Chef has had chance to learn from several years of Puppet
14Monday, 4 May 2009
![Page 15: Running the Show: Configuration Management with Chef](https://reader034.vdocument.in/reader034/viewer/2022052618/55281a2b550346a4588b4623/html5/thumbnails/15.jpg)
Architecture
Chef-client
Ohai
Node
Chef ServerChef-client
Ohai
Node
Chef-client
Ohai
Node
Chef-client
Ohai
Client
Chef Indexer
15Monday, 4 May 2009
![Page 16: Running the Show: Configuration Management with Chef](https://reader034.vdocument.in/reader034/viewer/2022052618/55281a2b550346a4588b4623/html5/thumbnails/16.jpg)
Getting started
16Monday, 4 May 2009
![Page 17: Running the Show: Configuration Management with Chef](https://reader034.vdocument.in/reader034/viewer/2022052618/55281a2b550346a4588b4623/html5/thumbnails/17.jpg)
Assemble your victims
• Use VMs for testing environment
• Ubuntu 8.10 or newer is the sweet spot
• VirtualBox is a free virtualization tool
• Identify a server and one or more clients
17Monday, 4 May 2009
![Page 18: Running the Show: Configuration Management with Chef](https://reader034.vdocument.in/reader034/viewer/2022052618/55281a2b550346a4588b4623/html5/thumbnails/18.jpg)
Prerequisites
• Two stage install: basics & bootstrap
• Minimal prerequisites: Ruby & RubyGems
• Install via Gems: ohai and chef
• Bootstrap differs for server and client
18Monday, 4 May 2009
![Page 19: Running the Show: Configuration Management with Chef](https://reader034.vdocument.in/reader034/viewer/2022052618/55281a2b550346a4588b4623/html5/thumbnails/19.jpg)
Server
• Apache + Passenger
• Provides administrative Web UI
• Users identified by OpenID
• Recipes defined by your chef repository
19Monday, 4 May 2009
![Page 20: Running the Show: Configuration Management with Chef](https://reader034.vdocument.in/reader034/viewer/2022052618/55281a2b550346a4588b4623/html5/thumbnails/20.jpg)
Client
• Invocation of chef-client
• One-time
• As a daemon
chef-client -i 3600 -s 600
20Monday, 4 May 2009
![Page 21: Running the Show: Configuration Management with Chef](https://reader034.vdocument.in/reader034/viewer/2022052618/55281a2b550346a4588b4623/html5/thumbnails/21.jpg)
Chef repository
• Contains configuration and cookbooks
• Clone the Opscode template to start
• Copy your configuration
21Monday, 4 May 2009
![Page 22: Running the Show: Configuration Management with Chef](https://reader034.vdocument.in/reader034/viewer/2022052618/55281a2b550346a4588b4623/html5/thumbnails/22.jpg)
First look at the server
22Monday, 4 May 2009
![Page 23: Running the Show: Configuration Management with Chef](https://reader034.vdocument.in/reader034/viewer/2022052618/55281a2b550346a4588b4623/html5/thumbnails/23.jpg)
First client run
23Monday, 4 May 2009
![Page 24: Running the Show: Configuration Management with Chef](https://reader034.vdocument.in/reader034/viewer/2022052618/55281a2b550346a4588b4623/html5/thumbnails/24.jpg)
Node attributes
• Explore with Web UI
• OS attributes provided by ohai
• Other attributes are configured by the installed cookbooks
• Attributes are mutable
24Monday, 4 May 2009
![Page 25: Running the Show: Configuration Management with Chef](https://reader034.vdocument.in/reader034/viewer/2022052618/55281a2b550346a4588b4623/html5/thumbnails/25.jpg)
Making a cookbook
• Cookbook is the unit of reuse in Chef
• Unsurprisingly, it contains recipes
• Generate one withrake new_cookbook COOKBOOK=hello_world
25Monday, 4 May 2009
![Page 26: Running the Show: Configuration Management with Chef](https://reader034.vdocument.in/reader034/viewer/2022052618/55281a2b550346a4588b4623/html5/thumbnails/26.jpg)
Inside the cookbook
• attributes — variables
• recipes — list of instructions (“resources”)
• files — files used by resources
• templates — ERB templates
• definitions — macros of resources
• libraries — Ruby to extend Chef DSL
26Monday, 4 May 2009
![Page 27: Running the Show: Configuration Management with Chef](https://reader034.vdocument.in/reader034/viewer/2022052618/55281a2b550346a4588b4623/html5/thumbnails/27.jpg)
Define an attribute
• Simple attributeattributes/my_name.rb
my_name “John Henry”
27Monday, 4 May 2009
![Page 28: Running the Show: Configuration Management with Chef](https://reader034.vdocument.in/reader034/viewer/2022052618/55281a2b550346a4588b4623/html5/thumbnails/28.jpg)
A simple recipe
template “/tmp/hello_world.txt” do source “hello_world.txt.erb” variables :my_name => node[:my_name] mode 00664 action :createend
• recipes/default.rb
28Monday, 4 May 2009
![Page 29: Running the Show: Configuration Management with Chef](https://reader034.vdocument.in/reader034/viewer/2022052618/55281a2b550346a4588b4623/html5/thumbnails/29.jpg)
The template
• templates/default/hello_world.txt.erb
Hello, <%= @my_name %>, how are you today?
29Monday, 4 May 2009
![Page 30: Running the Show: Configuration Management with Chef](https://reader034.vdocument.in/reader034/viewer/2022052618/55281a2b550346a4588b4623/html5/thumbnails/30.jpg)
Running the recipe
• Add the recipe to the node’s recipe list
• Invoke chef-client
• Default chef-client setup has client invoked periodically
30Monday, 4 May 2009
![Page 31: Running the Show: Configuration Management with Chef](https://reader034.vdocument.in/reader034/viewer/2022052618/55281a2b550346a4588b4623/html5/thumbnails/31.jpg)
When chef-client runs
• Node authenticates with server
• Libraries, attributes, definitions & recipes are synchronized
• Libraries, attributes, definitions & recipes compiled
• Node state is converged
• Everything happens on the node
31Monday, 4 May 2009
![Page 32: Running the Show: Configuration Management with Chef](https://reader034.vdocument.in/reader034/viewer/2022052618/55281a2b550346a4588b4623/html5/thumbnails/32.jpg)
Attributes & resources
32Monday, 4 May 2009
![Page 33: Running the Show: Configuration Management with Chef](https://reader034.vdocument.in/reader034/viewer/2022052618/55281a2b550346a4588b4623/html5/thumbnails/33.jpg)
Attributes
• May be simply defined, e.g. my_name “John Henry”
• Allow overriding, e.g. my_name “John Henry” unless attribute?(“my_name”)
• List values are regular arrays[“foo”, “bar”, “whizz”]
33Monday, 4 May 2009
![Page 34: Running the Show: Configuration Management with Chef](https://reader034.vdocument.in/reader034/viewer/2022052618/55281a2b550346a4588b4623/html5/thumbnails/34.jpg)
Attribute hashes
• Logical groupings of configuration information, e.g. Apache settings, network interface properties
• Class used is Mash (from extlib)
• so you can use :foo or ‘foo’ as a key
34Monday, 4 May 2009
![Page 35: Running the Show: Configuration Management with Chef](https://reader034.vdocument.in/reader034/viewer/2022052618/55281a2b550346a4588b4623/html5/thumbnails/35.jpg)
Advanced attributes
• Methods: attribute?() & recipe?()
• Access to recipes arrayrecipes << “hello_world” unless recipe?(“hello_world”)
35Monday, 4 May 2009
![Page 36: Running the Show: Configuration Management with Chef](https://reader034.vdocument.in/reader034/viewer/2022052618/55281a2b550346a4588b4623/html5/thumbnails/36.jpg)
Resources
• The steps that make up a recipe
package “git-core” do action :installend
• Resources are implemented via Providers
36Monday, 4 May 2009
![Page 37: Running the Show: Configuration Management with Chef](https://reader034.vdocument.in/reader034/viewer/2022052618/55281a2b550346a4588b4623/html5/thumbnails/37.jpg)
Package
package "tar" do version "1.16.1-1" action :installend
• Action can be install, upgrade, remove, purge
• Version is optional
37Monday, 4 May 2009
![Page 38: Running the Show: Configuration Management with Chef](https://reader034.vdocument.in/reader034/viewer/2022052618/55281a2b550346a4588b4623/html5/thumbnails/38.jpg)
Ruby gems
• Install gems with package toopackage “capistrano” do provider Chef::Provider::Package::Rubygemsend
• Easier:gem_package “capistrano”
• Can use source attribute for gem source
38Monday, 4 May 2009
![Page 39: Running the Show: Configuration Management with Chef](https://reader034.vdocument.in/reader034/viewer/2022052618/55281a2b550346a4588b4623/html5/thumbnails/39.jpg)
Remote files
• Copying remote files is easy
remote_file “/tmp/foo.png” do source “foo.png” owner “root” group “root” mode 0444 action :createend
• Where does the file live?
39Monday, 4 May 2009
![Page 40: Running the Show: Configuration Management with Chef](https://reader034.vdocument.in/reader034/viewer/2022052618/55281a2b550346a4588b4623/html5/thumbnails/40.jpg)
Search path
• Files and templates are searched for in the following order: FQDN, platform-version, platform, default
• For Ubuntu 9.04: myhost.example.com ubuntu-9.04 ubuntu default
40Monday, 4 May 2009
![Page 41: Running the Show: Configuration Management with Chef](https://reader034.vdocument.in/reader034/viewer/2022052618/55281a2b550346a4588b4623/html5/thumbnails/41.jpg)
More remote file fun
• File source can be a URL
source “http://warez.com/thing.tgz”
• Provide SHA256 hash to prevent needless downloading from chef-server each time
checksum “08da0021”
41Monday, 4 May 2009
![Page 42: Running the Show: Configuration Management with Chef](https://reader034.vdocument.in/reader034/viewer/2022052618/55281a2b550346a4588b4623/html5/thumbnails/42.jpg)
Links
• Symbolic or hard links
link “/usr/bin/randomthing1.8” do to “/usr/bin/randomthing”end
• Use link_type :hard or :symbolic (default)
42Monday, 4 May 2009
![Page 43: Running the Show: Configuration Management with Chef](https://reader034.vdocument.in/reader034/viewer/2022052618/55281a2b550346a4588b4623/html5/thumbnails/43.jpg)
File
• Control existence and attributes of a file, not its contents
file “/tmp/whatever” do owner “root” group “root” mode “0644” action :createend
• Other actions are touch, delete
43Monday, 4 May 2009
![Page 44: Running the Show: Configuration Management with Chef](https://reader034.vdocument.in/reader034/viewer/2022052618/55281a2b550346a4588b4623/html5/thumbnails/44.jpg)
Other FS resources
• directory — analog of the File resource
• remote_directory — recursive remote copy
44Monday, 4 May 2009
![Page 45: Running the Show: Configuration Management with Chef](https://reader034.vdocument.in/reader034/viewer/2022052618/55281a2b550346a4588b4623/html5/thumbnails/45.jpg)
Service
• Control system services from /etc/init.d and friends
• We can en/disable, start, stop & restart
service “my_daemon” do supports :restart => true action [ :enable, :start ]end
45Monday, 4 May 2009
![Page 46: Running the Show: Configuration Management with Chef](https://reader034.vdocument.in/reader034/viewer/2022052618/55281a2b550346a4588b4623/html5/thumbnails/46.jpg)
Other resources
• User
• Group
• Cron
• Route
• Mount
46Monday, 4 May 2009
![Page 47: Running the Show: Configuration Management with Chef](https://reader034.vdocument.in/reader034/viewer/2022052618/55281a2b550346a4588b4623/html5/thumbnails/47.jpg)
Execute
• Execute arbitrary command
command “mysql-stuff” do execute “/usr/bin/mysql </tmp/foo.sql” creates “/tmp/outfile.sql” environment {‘FOO’ => “bar”} action :run
end
47Monday, 4 May 2009
![Page 48: Running the Show: Configuration Management with Chef](https://reader034.vdocument.in/reader034/viewer/2022052618/55281a2b550346a4588b4623/html5/thumbnails/48.jpg)
Script
• bash, perl, python, ruby, csh
bash “install_foo” do user “root” cwd “/tmp” code <<-EOC wget http://example.org/foo.tgz tar xvf foo.tgz && cd foo ./configure && make install EOC
end
48Monday, 4 May 2009
![Page 49: Running the Show: Configuration Management with Chef](https://reader034.vdocument.in/reader034/viewer/2022052618/55281a2b550346a4588b4623/html5/thumbnails/49.jpg)
HTTP Request
• Useful for connecting to existing services
http_request “say_hello” do url “http://myserv.local/check_in” message :node => node[:fqdn] action :postend
• Posts a JSON payload
• GET by default
49Monday, 4 May 2009
![Page 50: Running the Show: Configuration Management with Chef](https://reader034.vdocument.in/reader034/viewer/2022052618/55281a2b550346a4588b4623/html5/thumbnails/50.jpg)
Resource tricks
50Monday, 4 May 2009
![Page 51: Running the Show: Configuration Management with Chef](https://reader034.vdocument.in/reader034/viewer/2022052618/55281a2b550346a4588b4623/html5/thumbnails/51.jpg)
Notifies
• Chain actionstemplate “/etc/my_daemon/my.cnf” do source “my.cnf.erb” notifies :restart, resources(:service => “my_daemon”)end
• By default, notification postponed until end of run, add :immediately as final argument to override
51Monday, 4 May 2009
![Page 52: Running the Show: Configuration Management with Chef](https://reader034.vdocument.in/reader034/viewer/2022052618/55281a2b550346a4588b4623/html5/thumbnails/52.jpg)
Action :nothing
• If you want a resource to run only on a notify, specify action :nothing
execute "index-gem-repository" do command "gem generate_index -d /srv/gems" action :nothingend
52Monday, 4 May 2009
![Page 53: Running the Show: Configuration Management with Chef](https://reader034.vdocument.in/reader034/viewer/2022052618/55281a2b550346a4588b4623/html5/thumbnails/53.jpg)
Conditional resources
• Use only_if and not_if to control resource execution
• Takes either shell commands or Ruby blocks, e.g.
only_if do IO.read(“/tmp/foo”).chomp == ‘bar’end
53Monday, 4 May 2009
![Page 54: Running the Show: Configuration Management with Chef](https://reader034.vdocument.in/reader034/viewer/2022052618/55281a2b550346a4588b4623/html5/thumbnails/54.jpg)
Platform specifics
• Selective resource executiononly_if do platform?(“ubuntu”) end
• Alter package namepackage "libwww-perl" do case node[:platform] when "centos" name "perl-libwww-perl" end action :upgradeend
54Monday, 4 May 2009
![Page 55: Running the Show: Configuration Management with Chef](https://reader034.vdocument.in/reader034/viewer/2022052618/55281a2b550346a4588b4623/html5/thumbnails/55.jpg)
OpsCode Cookbook
55Monday, 4 May 2009
![Page 56: Running the Show: Configuration Management with Chef](https://reader034.vdocument.in/reader034/viewer/2022052618/55281a2b550346a4588b4623/html5/thumbnails/56.jpg)
Opscode cookbooks
• http://github.com/opscode/cookbooks
• Integral part of the Chef project
• If you want it, it’s probably already there
• common configurations
• smoothing over platform specifics
56Monday, 4 May 2009
![Page 57: Running the Show: Configuration Management with Chef](https://reader034.vdocument.in/reader034/viewer/2022052618/55281a2b550346a4588b4623/html5/thumbnails/57.jpg)
Using the cookbooks
• Keep your own stuff in site-cookbooks
• Use git to add cookbooks as a submodule
git submodule add git://github.com/opscode/cookbooks.git cookbooksgit submodule initgit submodule update
57Monday, 4 May 2009
![Page 58: Running the Show: Configuration Management with Chef](https://reader034.vdocument.in/reader034/viewer/2022052618/55281a2b550346a4588b4623/html5/thumbnails/58.jpg)
3rd party cookbooks
• The cookbook_path from the server config specifies precedence
• By default site-cookbooks overrides cookbooks
• You can adapt recipes simply by replacing the parts you wish
58Monday, 4 May 2009
![Page 59: Running the Show: Configuration Management with Chef](https://reader034.vdocument.in/reader034/viewer/2022052618/55281a2b550346a4588b4623/html5/thumbnails/59.jpg)
apache2 cookbook
• Attributes configure basic preferences (ports, timeout, keepalive)
• Default recipe sets up sane configuration
• apache2:: namespace includes recipes for common modules
59Monday, 4 May 2009
![Page 60: Running the Show: Configuration Management with Chef](https://reader034.vdocument.in/reader034/viewer/2022052618/55281a2b550346a4588b4623/html5/thumbnails/60.jpg)
Overriding attributes
• If you control cookbook, easy enough to set a default
• Per-node customizations can be made in the UI
• To set new defaults, override selectively in site-cookbooks
60Monday, 4 May 2009
![Page 61: Running the Show: Configuration Management with Chef](https://reader034.vdocument.in/reader034/viewer/2022052618/55281a2b550346a4588b4623/html5/thumbnails/61.jpg)
apache2 definitions
• Macro for a2ensite & friends
apache_site “my_app” :enable => trueend
• web_app — wraps most of the common configuration for a web app (e.g. Rails)
61Monday, 4 May 2009
![Page 62: Running the Show: Configuration Management with Chef](https://reader034.vdocument.in/reader034/viewer/2022052618/55281a2b550346a4588b4623/html5/thumbnails/62.jpg)
mysql cookbook
• mysql::client, mysql::server
• EC2-aware
62Monday, 4 May 2009
![Page 63: Running the Show: Configuration Management with Chef](https://reader034.vdocument.in/reader034/viewer/2022052618/55281a2b550346a4588b4623/html5/thumbnails/63.jpg)
Rails cookbook
• Provides installation recipe and attributes for tuning
• rails[:version]
• rails[:environment]
• rails[:max_pool_size]
• Provides web_app template you can copy
63Monday, 4 May 2009
![Page 64: Running the Show: Configuration Management with Chef](https://reader034.vdocument.in/reader034/viewer/2022052618/55281a2b550346a4588b4623/html5/thumbnails/64.jpg)
Chef and Rails
64Monday, 4 May 2009
![Page 65: Running the Show: Configuration Management with Chef](https://reader034.vdocument.in/reader034/viewer/2022052618/55281a2b550346a4588b4623/html5/thumbnails/65.jpg)
How Chef can help
• Configuration
• Deployment
• Configuration is the better trodden path
65Monday, 4 May 2009
![Page 66: Running the Show: Configuration Management with Chef](https://reader034.vdocument.in/reader034/viewer/2022052618/55281a2b550346a4588b4623/html5/thumbnails/66.jpg)
Example configuration
• Naive Chef recipe to get all the prequisites in place for an instance of Expectnation
66Monday, 4 May 2009
![Page 67: Running the Show: Configuration Management with Chef](https://reader034.vdocument.in/reader034/viewer/2022052618/55281a2b550346a4588b4623/html5/thumbnails/67.jpg)
Worked example
• Create and deploy a basic Rails app
67Monday, 4 May 2009
![Page 68: Running the Show: Configuration Management with Chef](https://reader034.vdocument.in/reader034/viewer/2022052618/55281a2b550346a4588b4623/html5/thumbnails/68.jpg)
chef-deploy
• A resource that implements Rails application deployment
• Models Capistrano’s cached_deploy
• In rapid development, used at EngineYard
• http://github.com/ezmobius/chef-deploy
68Monday, 4 May 2009
![Page 69: Running the Show: Configuration Management with Chef](https://reader034.vdocument.in/reader034/viewer/2022052618/55281a2b550346a4588b4623/html5/thumbnails/69.jpg)
deploy "/data/#{app}" do repo "git://server/path/app.git" branch "HEAD" user "myuser" enable_submodules true migrate true migration_command "rake db:migrate" environment "production" shallow_clone true revision '5DE77F8ADC' restart_command “...” role “myrole” action :deployend
69Monday, 4 May 2009
![Page 70: Running the Show: Configuration Management with Chef](https://reader034.vdocument.in/reader034/viewer/2022052618/55281a2b550346a4588b4623/html5/thumbnails/70.jpg)
Callbacks
• Ruby scripts in your app’s deploy/
• before_migrate, before_symlink, before_restart, after_restart
• Rails environment and ‘role’ passed as arguments to callback
• Could control this via role node[:myapp][:role]
70Monday, 4 May 2009
![Page 71: Running the Show: Configuration Management with Chef](https://reader034.vdocument.in/reader034/viewer/2022052618/55281a2b550346a4588b4623/html5/thumbnails/71.jpg)
Single source for gem dependencies
• Specify gems in gems.yml in your app’s root
- :name: foo :version: "1.3"- :name: bar :version: "2.0.1"
71Monday, 4 May 2009
![Page 72: Running the Show: Configuration Management with Chef](https://reader034.vdocument.in/reader034/viewer/2022052618/55281a2b550346a4588b4623/html5/thumbnails/72.jpg)
Deployment strategy
• Unlikely you want deploy to be attemped with the default chef-client behavior
• chef-deploy developed against a Chef Solo world view: explicit execution
• Use attribute to control deployment
• Work in progress
72Monday, 4 May 2009
![Page 73: Running the Show: Configuration Management with Chef](https://reader034.vdocument.in/reader034/viewer/2022052618/55281a2b550346a4588b4623/html5/thumbnails/73.jpg)
Gotchas
• Chef-deploy assumes shared config/database.yml
• Usual package/gem conflicts
• Don’t install rake from packages!
73Monday, 4 May 2009
![Page 74: Running the Show: Configuration Management with Chef](https://reader034.vdocument.in/reader034/viewer/2022052618/55281a2b550346a4588b4623/html5/thumbnails/74.jpg)
Chef Solo
74Monday, 4 May 2009
![Page 75: Running the Show: Configuration Management with Chef](https://reader034.vdocument.in/reader034/viewer/2022052618/55281a2b550346a4588b4623/html5/thumbnails/75.jpg)
Server-less operation
• Bundle up the cookbooks in a tarball
• Set attributes in a JSON file
• Good to go!
75Monday, 4 May 2009
![Page 76: Running the Show: Configuration Management with Chef](https://reader034.vdocument.in/reader034/viewer/2022052618/55281a2b550346a4588b4623/html5/thumbnails/76.jpg)
Deploying with solo
• Tar up your cookbooks
• Create a solo.rbfile_cache_path “/tmp/chef-solo”cookbook_path “/tmp/chef-solo/cookbooks”
• Currently, must have unified cookbook tree
76Monday, 4 May 2009
![Page 77: Running the Show: Configuration Management with Chef](https://reader034.vdocument.in/reader034/viewer/2022052618/55281a2b550346a4588b4623/html5/thumbnails/77.jpg)
Deploying with solo (2)
• Create your JSON, e.g.{ “recipes”: “chef-server”, “myvar”: “foo” }
• Executechef-solo -c solo.rb -j chef.json -r http://path/to/tarball.tgz
• JSON path can be URL too
77Monday, 4 May 2009
![Page 78: Running the Show: Configuration Management with Chef](https://reader034.vdocument.in/reader034/viewer/2022052618/55281a2b550346a4588b4623/html5/thumbnails/78.jpg)
Why Chef Solo?
• When you don’t or can’t control access to the server
• When clients aren’t in the same security zone
• When you care about installation rather than long-term maintenance
78Monday, 4 May 2009
![Page 79: Running the Show: Configuration Management with Chef](https://reader034.vdocument.in/reader034/viewer/2022052618/55281a2b550346a4588b4623/html5/thumbnails/79.jpg)
Development patterns
79Monday, 4 May 2009
![Page 80: Running the Show: Configuration Management with Chef](https://reader034.vdocument.in/reader034/viewer/2022052618/55281a2b550346a4588b4623/html5/thumbnails/80.jpg)
Git strategy
• Use submodules to bring in 3rd party cookbooks
• Develop against testbed, push to shared repository
• Server install rule does a git pull
80Monday, 4 May 2009
![Page 81: Running the Show: Configuration Management with Chef](https://reader034.vdocument.in/reader034/viewer/2022052618/55281a2b550346a4588b4623/html5/thumbnails/81.jpg)
VM testbed
• Use a VM tool that supports snapshotting
• VirtualBox is free
• VMware good, supported by Poolparty
• Use Avahi/Bonjour for convenience
81Monday, 4 May 2009
![Page 82: Running the Show: Configuration Management with Chef](https://reader034.vdocument.in/reader034/viewer/2022052618/55281a2b550346a4588b4623/html5/thumbnails/82.jpg)
Attribute control
• Particularly useful with chef-solo, transfer the onus of control over to the attributes
• Control recipe execution via, eg. a ‘role’ attribute
• Help DRY by listing packages, etc, in attributes
82Monday, 4 May 2009
![Page 83: Running the Show: Configuration Management with Chef](https://reader034.vdocument.in/reader034/viewer/2022052618/55281a2b550346a4588b4623/html5/thumbnails/83.jpg)
Refactor into definitions & attributes
• For maintainability, consider refactoring obvious components into definitions
• e.g. the directory creation stage of a Rails app (what cap deploy:setup does)
83Monday, 4 May 2009
![Page 84: Running the Show: Configuration Management with Chef](https://reader034.vdocument.in/reader034/viewer/2022052618/55281a2b550346a4588b4623/html5/thumbnails/84.jpg)
REST API
84Monday, 4 May 2009
![Page 85: Running the Show: Configuration Management with Chef](https://reader034.vdocument.in/reader034/viewer/2022052618/55281a2b550346a4588b4623/html5/thumbnails/85.jpg)
Chef’s REST API
• Chef’s REST API is pretty mature
• Reused a lot internally
• Best way to programmatically integrate
• Documentation scarce for now
85Monday, 4 May 2009
![Page 86: Running the Show: Configuration Management with Chef](https://reader034.vdocument.in/reader034/viewer/2022052618/55281a2b550346a4588b4623/html5/thumbnails/86.jpg)
What can you do with the API?
• Programmatic access to the server
• Add remove/recipes from nodes
• Interrogate and set attributes
• Perform searches
86Monday, 4 May 2009
![Page 87: Running the Show: Configuration Management with Chef](https://reader034.vdocument.in/reader034/viewer/2022052618/55281a2b550346a4588b4623/html5/thumbnails/87.jpg)
API authentication
• Register in the same way a node does
Chef::Config.from_file( “/etc/chef/server.rb”)@rest = Chef::REST.new( Chef::Config[:registration_url])@rest.register(user, password)
• Thereafter, [email protected](user, password)
87Monday, 4 May 2009
![Page 88: Running the Show: Configuration Management with Chef](https://reader034.vdocument.in/reader034/viewer/2022052618/55281a2b550346a4588b4623/html5/thumbnails/88.jpg)
Manipulating nodesnode = @rest.get_rest(“nodes/foo_example_com”)
puts node.recipes.inspectnode.recipes << “apache2”
puts node[:myattr].inspectnode[:myattr] = { :foo => “bar” }
@rest.put_rest(“nodes/foo_example_com”, node)
88Monday, 4 May 2009
![Page 89: Running the Show: Configuration Management with Chef](https://reader034.vdocument.in/reader034/viewer/2022052618/55281a2b550346a4588b4623/html5/thumbnails/89.jpg)
Knife
• Basic command line interface to the server
• For now, get from http://gist.github.com/104080
89Monday, 4 May 2009
![Page 90: Running the Show: Configuration Management with Chef](https://reader034.vdocument.in/reader034/viewer/2022052618/55281a2b550346a4588b4623/html5/thumbnails/90.jpg)
Searching
90Monday, 4 May 2009
![Page 91: Running the Show: Configuration Management with Chef](https://reader034.vdocument.in/reader034/viewer/2022052618/55281a2b550346a4588b4623/html5/thumbnails/91.jpg)
Searching the server
• Powerful feature
• Not that mature yet
• Ferret indexes the Chef Server database
• Queries expressed in FQL
91Monday, 4 May 2009
![Page 92: Running the Show: Configuration Management with Chef](https://reader034.vdocument.in/reader034/viewer/2022052618/55281a2b550346a4588b4623/html5/thumbnails/92.jpg)
Access from recipes
• search(INDEX, QUERY)
• search(:node, “*”) reports every node in the DB
• Find the IP of every node running Apachesearch(:node, “recipe:apache2”).collect {|n| n[‘ipaddress’]}
92Monday, 4 May 2009
![Page 93: Running the Show: Configuration Management with Chef](https://reader034.vdocument.in/reader034/viewer/2022052618/55281a2b550346a4588b4623/html5/thumbnails/93.jpg)
Access from REST API
• As implemented in the Web UI
@rest.get_rest( "search/node?q=recipe:apache2")
93Monday, 4 May 2009
![Page 94: Running the Show: Configuration Management with Chef](https://reader034.vdocument.in/reader034/viewer/2022052618/55281a2b550346a4588b4623/html5/thumbnails/94.jpg)
Chef & EC2
94Monday, 4 May 2009
![Page 95: Running the Show: Configuration Management with Chef](https://reader034.vdocument.in/reader034/viewer/2022052618/55281a2b550346a4588b4623/html5/thumbnails/95.jpg)
In OpsCode cookbooks
• ec2 cookbook
• EC2 awareness in, e.g. mysql recipes
• Bunch of handy EC2 attributes exposed
95Monday, 4 May 2009
![Page 96: Running the Show: Configuration Management with Chef](https://reader034.vdocument.in/reader034/viewer/2022052618/55281a2b550346a4588b4623/html5/thumbnails/96.jpg)
Poolparty
• Configure and deploy to the cloud
• Uses Chef
• http://poolpartyrb.com/
96Monday, 4 May 2009
![Page 97: Running the Show: Configuration Management with Chef](https://reader034.vdocument.in/reader034/viewer/2022052618/55281a2b550346a4588b4623/html5/thumbnails/97.jpg)
What Poolparty does
• Launches VM (EC2 or VMware), waits for IP and ssh
• Bootstrap: rsyncs dependencies and installs
• Configure: compile cookbooks, rsyncs, executes Chef Solo
• Verifies installation
97Monday, 4 May 2009
![Page 98: Running the Show: Configuration Management with Chef](https://reader034.vdocument.in/reader034/viewer/2022052618/55281a2b550346a4588b4623/html5/thumbnails/98.jpg)
Community resources
• Wiki is a great and ever-improving reference http://wiki.opscode.com/display/chef/Home
• IRCirc://irc.freenode.net/chef
• Mailing list
98Monday, 4 May 2009
![Page 99: Running the Show: Configuration Management with Chef](https://reader034.vdocument.in/reader034/viewer/2022052618/55281a2b550346a4588b4623/html5/thumbnails/99.jpg)
The future
• Chef is evolving rapidly
• Platform support improving through contributions
• Opscode-agent
• nanite
• selective resource execution
99Monday, 4 May 2009
![Page 100: Running the Show: Configuration Management with Chef](https://reader034.vdocument.in/reader034/viewer/2022052618/55281a2b550346a4588b4623/html5/thumbnails/100.jpg)
In conclusion
• Please rate this tutorial and leave comments http://bit.ly/chef-rails
• Q&A
• Thank you!
100Monday, 4 May 2009