In the Kitchen
Cooking with Chef
Tyler Hunt
 @tylerhunt
homegrown apps
Tweeter Phone
listen to your tweets
Problem
System
Administration
Configuration
Management
External DSL
     vs.
Internal DSL
SSL
  vs.
OpenID
XML-RPC
   vs.
 RESTful
Test::Unit + RSpec + Mocha
             vs.
           RSpec
Lines of Code




  Puppet                  Chef

      http://www.ohloh.net/p/compare?project_0=puppet&project_1=opscode-...
gem install chef
Opscode
“Chef is a state based,
declarative configuration
management engine.You
define recipes of how you
want your system to look
a...
OHAI
gem install ohai
./bin/ohai
{
    quot;kernelquot;: {
       quot;machinequot;: quot;x86_64quot;,
       quot;namequot;: quot;Linuxquot;,
       quot;...
Nodes
Cookbooks
Recipes
Definitions
    def•i•ni•tions
(děf'ə-nĭsh'ənz) n. pl.
Attributes
Libraries
Files
Templates
Templates
Templates
Templates
Templates
Templates
Templates
cookbooks/
  my_cookbook/
    attributes/
    definitions/
    files/
    libraries/
    recipes/
    templates/
gems Mash.new unless attribute?(quot;gemsquot;)

gems[:rake] ||= {
  :version => quot;0.8.3quot;
}

gems[:nokogiri] ||= {
...
{
    quot;gemsquot;: {
      quot;rakequot;: {
         quot;versionquot;: quot;0.8.3quot;
      },
      quot;nokogiriqu...
node[:gems].each do |name, gem|
  gem_package name do
    version gem[:version] if gem[:version]
    source gem[:source] i...
node[:gems].each do |name, gem|
  gem_package name do
    version gem[:version] if gem[:version]
    source gem[:source] i...
Resources

     Α
 Β       Γ
cron
    execute
              directory
       file
              group
       user
              link
    package
      ...
Providers
node[:gems].each do |name, gem|
  gem_package name do
    version gem[:version] if gem[:version]
    source gem[:source] i...
directory quot;/tmp/somethingquot; do
  owner quot;rootquot;
  group quot;rootquot;
  mode 0755
  action :create
end
file quot;/tmp/somethingquot; do
  owner quot;rootquot;
  group quot;rootquot;
  mode 0755
  action :touch
end
cron quot;noopquot; do
  hour quot;5quot;
  command quot;/bin/truequot;
end
execute quot;slapaddquot; do
  command quot;slapadd < /tmp/something.ldifquot;
  creates quot;/var/lib/slapd/uid.bdbquot;
...
group quot;adminquot; do
  gid 999
end
user quot;randomquot; do
  comment quot;Random Userquot;
  uid quot;1000quot;
  gid quot;usersquot;
  home quot;/home/rand...
link quot;/tmp/passwdquot; do
  to quot;/etc/passwdquot;
  link_type :symbolic
end
package quot;tarquot; do
  version quot;1.16.1-1quot;
  action :install
end
# file from cookbook
remote_file quot;/tmp/testquot; do
  source quot;testquot;
  mode 0644
end

# file from remote source...
remote_directory quot;/tmp/remote_somethingquot; do
  source quot;somethingquot;
  files_backup 10
  files_owner quot;root...
route quot;20.0.0.0quot; do
  gateway quot;10.0.0.20quot;
  metric 5
  route_type :net
  netmask quot;255.255.0.0quot;
end
script quot;install_somethingquot; do
  interpreter quot;bashquot;
  user quot;rootquot;
  cwd quot;/tmpquot;
  code <<-EO...
service quot;example_servicequot; do
  case node[:platform]
  when quot;CentOSquot;, quot;RedHatquot;, quot;Fedoraquot;
  ...
template quot;/etc/config.confquot; do
  source quot;config.conf.erbquot;
  variables({
     :timeout => 360
  })
end
http_request quot;posting dataquot; do
  url quot;http://example.com/check_inquot;
  message :some => quot;dataquot;
end
http://flickr.com/photos/philipyk/160559925/


http://flickr.com/photos/florin_mogos/2523984446/


http://flickr.com/photos/gi...
http://radlab.cs.berkeley.edu/wiki/Chef

http://junglist.gen.nz/chef-vs-puppet/

http://wiki.opscode.com/display/chef/Home...
Thank You
Cooking with Chef
Cooking with Chef
Cooking with Chef
Cooking with Chef
Cooking with Chef
Cooking with Chef
Cooking with Chef
Upcoming SlideShare
Loading in …5
×

Cooking with Chef

2,159 views

Published on

If you’re tired of running the same commands over and over when setting up your servers, you’ll love Chef. It’s a systems integration framework that allows you to use a Ruby DSL to manage your system configurations, and then easily deploy them across your entire infrastructure, à la Capistrano. Tyler will be breaking down the various components of Chef, and showing some example configurations to get you cooking.

Published in: Technology

Cooking with Chef

  1. 1. In the Kitchen Cooking with Chef
  2. 2. Tyler Hunt @tylerhunt
  3. 3. homegrown apps
  4. 4. Tweeter Phone listen to your tweets
  5. 5. Problem
  6. 6. System Administration
  7. 7. Configuration Management
  8. 8. External DSL vs. Internal DSL
  9. 9. SSL vs. OpenID
  10. 10. XML-RPC vs. RESTful
  11. 11. Test::Unit + RSpec + Mocha vs. RSpec
  12. 12. Lines of Code Puppet Chef http://www.ohloh.net/p/compare?project_0=puppet&project_1=opscode-chef
  13. 13. gem install chef
  14. 14. Opscode
  15. 15. “Chef is a state based, declarative configuration management engine.You define recipes of how you want your system to look and then chef makes it so.” — Ezra Zygmuntowicz
  16. 16. OHAI
  17. 17. gem install ohai
  18. 18. ./bin/ohai
  19. 19. { quot;kernelquot;: { quot;machinequot;: quot;x86_64quot;, quot;namequot;: quot;Linuxquot;, quot;osquot;: quot;GNU/Linuxquot;, quot;versionquot;: quot;#1 SMP Wed Aug 20 21:08:51 UTC 2008quot;, quot;releasequot;: quot;2.6.24-19-xenquot; }, quot;uptime_secondsquot;: 12043422, quot;platform_versionquot;: quot;8.04quot;, quot;platformquot;: quot;ubuntuquot;, quot;virtualizationquot;: { quot;rolequot;: quot;guestquot;, quot;emulatorquot;: quot;xenquot; }, quot;osquot;: quot;linuxquot;, quot;idletimequot;: quot;115 days 23 hours 34 minutes 06 secondsquot;, quot;idletime_secondsquot;: 10020846, quot;lsbquot;: { quot;idquot;: quot;Ubuntuquot;, quot;descriptionquot;: quot;quot;Ubuntu 8.04.1quot;quot;, quot;codenamequot;: quot;hardyquot;, quot;releasequot;: quot;8.04quot; }, quot;os_versionquot;: quot;2.6.24-19-xenquot; }
  20. 20. Nodes
  21. 21. Cookbooks
  22. 22. Recipes
  23. 23. Definitions def•i•ni•tions (děf'ə-nĭsh'ənz) n. pl.
  24. 24. Attributes
  25. 25. Libraries
  26. 26. Files
  27. 27. Templates Templates Templates Templates Templates Templates Templates
  28. 28. cookbooks/ my_cookbook/ attributes/ definitions/ files/ libraries/ recipes/ templates/
  29. 29. gems Mash.new unless attribute?(quot;gemsquot;) gems[:rake] ||= { :version => quot;0.8.3quot; } gems[:nokogiri] ||= { :version => quot;1.0.5quot; :source => quot;http://gems.github.com/quot; }
  30. 30. { quot;gemsquot;: { quot;rakequot;: { quot;versionquot;: quot;0.8.3quot; }, quot;nokogiriquot;: { quot;versionquot;: quot;1.0.5quot;, quot;sourcequot;: quot;http://gems.github.comquot; } } }
  31. 31. node[:gems].each do |name, gem| gem_package name do version gem[:version] if gem[:version] source gem[:source] if gem[:source] action :install end end
  32. 32. node[:gems].each do |name, gem| gem_package name do version gem[:version] if gem[:version] source gem[:source] if gem[:source] action :install end end
  33. 33. Resources Α Β Γ
  34. 34. cron execute directory file group user link package remote_directory remote_file route script service template http_request
  35. 35. Providers
  36. 36. node[:gems].each do |name, gem| gem_package name do version gem[:version] if gem[:version] source gem[:source] if gem[:source] action :install end end
  37. 37. directory quot;/tmp/somethingquot; do owner quot;rootquot; group quot;rootquot; mode 0755 action :create end
  38. 38. file quot;/tmp/somethingquot; do owner quot;rootquot; group quot;rootquot; mode 0755 action :touch end
  39. 39. cron quot;noopquot; do hour quot;5quot; command quot;/bin/truequot; end
  40. 40. execute quot;slapaddquot; do command quot;slapadd < /tmp/something.ldifquot; creates quot;/var/lib/slapd/uid.bdbquot; action :run end
  41. 41. group quot;adminquot; do gid 999 end
  42. 42. user quot;randomquot; do comment quot;Random Userquot; uid quot;1000quot; gid quot;usersquot; home quot;/home/randomquot; shell quot;/bin/zshquot; password quot;$1$JJsvHslV$szsCjVEroftprNn4JHtDi.quot; end
  43. 43. link quot;/tmp/passwdquot; do to quot;/etc/passwdquot; link_type :symbolic end
  44. 44. package quot;tarquot; do version quot;1.16.1-1quot; action :install end
  45. 45. # file from cookbook remote_file quot;/tmp/testquot; do source quot;testquot; mode 0644 end # file from remote source remote_file quot;/tmp/testfilequot; do source quot;http://example.com/files/testquot; mode 0644 end
  46. 46. remote_directory quot;/tmp/remote_somethingquot; do source quot;somethingquot; files_backup 10 files_owner quot;rootquot; files_group quot;rootquot; files_mode 0644 owner quot;nobodyquot; group quot;nobodyquot; mode 0755 end
  47. 47. route quot;20.0.0.0quot; do gateway quot;10.0.0.20quot; metric 5 route_type :net netmask quot;255.255.0.0quot; end
  48. 48. script quot;install_somethingquot; do interpreter quot;bashquot; user quot;rootquot; cwd quot;/tmpquot; code <<-EOH wget http://example.com/tarball.tar.gz tar -zxf tarball.tar.gz cd tarball ./configure make make install EOH end
  49. 49. service quot;example_servicequot; do case node[:platform] when quot;CentOSquot;, quot;RedHatquot;, quot;Fedoraquot; service_name quot;redhat_namequot; else service_name quot;other_namequot; end supports :restart => true action [ :enable, :start ] end
  50. 50. template quot;/etc/config.confquot; do source quot;config.conf.erbquot; variables({ :timeout => 360 }) end
  51. 51. http_request quot;posting dataquot; do url quot;http://example.com/check_inquot; message :some => quot;dataquot; end
  52. 52. http://flickr.com/photos/philipyk/160559925/ http://flickr.com/photos/florin_mogos/2523984446/ http://flickr.com/photos/giorgiocardellini/271092412/ http://flickr.com/photos/onkel_wart/2487637968/ http://flickr.com/photos/dunechaser/161509118/
  53. 53. http://radlab.cs.berkeley.edu/wiki/Chef http://junglist.gen.nz/chef-vs-puppet/ http://wiki.opscode.com/display/chef/Home http://brainspl.at/articles/2009/01/15/ http://brainspl.at/articles/2009/01/31/
  54. 54. Thank You

×