cooking with chef

61
In the Kitchen Cooking with Chef

Upload: orlandorubyusersgroup

Post on 07-May-2015

1.942 views

Category:

Technology


0 download

DESCRIPTION

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.

TRANSCRIPT

Page 1: Cooking with Chef

In the KitchenCooking with Chef

Page 2: Cooking with Chef

Tyler Hunt@tylerhunt

Page 3: Cooking with Chef

homegrown apps

Page 4: Cooking with Chef

Tweeter Phonelisten to your tweets

Page 5: Cooking with Chef

Problem

Page 6: Cooking with Chef

SystemAdministration

Page 7: Cooking with Chef
Page 8: Cooking with Chef
Page 9: Cooking with Chef

ConfigurationManagement

Page 10: Cooking with Chef
Page 11: Cooking with Chef
Page 12: Cooking with Chef

External DSLvs.

Internal DSL

Page 13: Cooking with Chef

SSLvs.

OpenID

Page 14: Cooking with Chef

XML-RPCvs.

RESTful

Page 15: Cooking with Chef

Test::Unit + RSpec + Mochavs.

RSpec

Page 16: Cooking with Chef

Puppet Chef

Lines of Code

http://www.ohloh.net/p/compare?project_0=puppet&project_1=opscode-chef

Page 17: Cooking with Chef
Page 18: Cooking with Chef

gem install chef

Page 19: Cooking with Chef

Opscode

Page 20: Cooking with Chef
Page 21: Cooking with Chef

“Chef is a state based,declarative configurationmanagement engine. Youdefine recipes of how youwant your system to lookand then chef makes it so.”

— Ezra Zygmuntowicz

Page 22: Cooking with Chef

OHAI

Page 23: Cooking with Chef

gem install ohai

Page 24: Cooking with Chef

./bin/ohai

Page 25: Cooking with Chef

{ "kernel": { "machine": "x86_64", "name": "Linux", "os": "GNU\/Linux", "version": "#1 SMP Wed Aug 20 21:08:51 UTC 2008", "release": "2.6.24-19-xen" }, "uptime_seconds": 12043422, "platform_version": "8.04", "platform": "ubuntu", "virtualization": { "role": "guest", "emulator": "xen" }, "os": "linux", "idletime": "115 days 23 hours 34 minutes 06 seconds", "idletime_seconds": 10020846, "lsb": { "id": "Ubuntu", "description": "\"Ubuntu 8.04.1\"", "codename": "hardy", "release": "8.04" }, "os_version": "2.6.24-19-xen"}

Page 26: Cooking with Chef
Page 27: Cooking with Chef

Nodes

Page 28: Cooking with Chef

Cookbooks

Page 29: Cooking with Chef

Recipes

Page 30: Cooking with Chef

Definitionsdef•i•ni•tions

(děf'ə-nĭsh'ənz) n. pl.

Page 31: Cooking with Chef

Attributes

Page 32: Cooking with Chef

Libraries

Page 33: Cooking with Chef

Files

Page 34: Cooking with Chef

TemplatesTemplatesTemplatesTemplatesTemplatesTemplatesTemplatesTemplates

Page 35: Cooking with Chef

cookbooks/ my_cookbook/ attributes/ definitions/ files/ libraries/ recipes/ templates/

Page 36: Cooking with Chef

gems Mash.new unless attribute?("gems")

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

gems[:nokogiri] ||= { :version => "1.0.5" :source => "http://gems.github.com/"}

Page 37: Cooking with Chef

{ "gems": { "rake": { "version": "0.8.3" }, "nokogiri": { "version": "1.0.5", "source": "http://gems.github.com" } }}

Page 38: Cooking with Chef

node[:gems].each do |name, gem| gem_package name do version gem[:version] if gem[:version] source gem[:source] if gem[:source] action :install endend

Page 39: Cooking with Chef

node[:gems].each do |name, gem| gem_package name do version gem[:version] if gem[:version] source gem[:source] if gem[:source] action :install endend

Page 40: Cooking with Chef

Resources

ΓΒΑ

Page 41: Cooking with Chef

execute

file

user

package

remote_file

script

template

cron

directory

group

link

remote_directory

route

service

http_request

Page 42: Cooking with Chef

Providers

Page 43: Cooking with Chef

node[:gems].each do |name, gem| gem_package name do version gem[:version] if gem[:version] source gem[:source] if gem[:source] action :install endend

Page 44: Cooking with Chef

directory "/tmp/something" do owner "root" group "root" mode 0755 action :createend

Page 45: Cooking with Chef

file "/tmp/something" do owner "root" group "root" mode 0755 action :touchend

Page 46: Cooking with Chef

cron "noop" do hour "5" command "/bin/true"end

Page 47: Cooking with Chef

execute "slapadd" do command "slapadd < /tmp/something.ldif" creates "/var/lib/slapd/uid.bdb" action :runend

Page 48: Cooking with Chef

group "admin" do gid 999end

Page 49: Cooking with Chef

user "random" do comment "Random User" uid "1000" gid "users" home "/home/random" shell "/bin/zsh" password "$1$JJsvHslV$szsCjVEroftprNn4JHtDi."end

Page 50: Cooking with Chef

link "/tmp/passwd" do to "/etc/passwd" link_type :symbolicend

Page 51: Cooking with Chef

package "tar" do version "1.16.1-1" action :installend

Page 52: Cooking with Chef

# file from cookbookremote_file "/tmp/test" do source "test" mode 0644end

# file from remote sourceremote_file "/tmp/testfile" do source "http://example.com/files/test" mode 0644end

Page 53: Cooking with Chef

remote_directory "/tmp/remote_something" do source "something" files_backup 10 files_owner "root" files_group "root" files_mode 0644 owner "nobody" group "nobody" mode 0755end

Page 54: Cooking with Chef

route "20.0.0.0" do gateway "10.0.0.20" metric 5 route_type :net netmask "255.255.0.0"end

Page 55: Cooking with Chef

script "install_something" do interpreter "bash" user "root" cwd "/tmp" code <<-EOH wget http://example.com/tarball.tar.gz tar -zxf tarball.tar.gz cd tarball ./configure make make install EOHend

Page 56: Cooking with Chef

service "example_service" do case node[:platform] when "CentOS", "RedHat", "Fedora" service_name "redhat_name" else service_name "other_name" end supports :restart => true action [ :enable, :start ]end

Page 57: Cooking with Chef

template "/etc/config.conf" do source "config.conf.erb" variables({ :timeout => 360 })end

Page 58: Cooking with Chef

http_request "posting data" do url "http://example.com/check_in" message :some => "data"end

Page 59: Cooking with Chef

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/

Page 60: Cooking with Chef

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/

Page 61: Cooking with Chef

Thank You