![Page 1: 5 Things You Always Wanted to Know About Chefcasitconf.org › casitconf13 › slides › Five-Things-About-Chef.pdf · 5 Things You Always Wanted to Know About Chef But Were Afraid](https://reader030.vdocuments.site/reader030/viewer/2022041109/5f0dc6a97e708231d43c0747/html5/thumbnails/1.jpg)
5 Things You Always Wanted to Know About Chef
But Were Afraid to Ask
Nathen [email protected]
@nathenharvey
![Page 2: 5 Things You Always Wanted to Know About Chefcasitconf.org › casitconf13 › slides › Five-Things-About-Chef.pdf · 5 Things You Always Wanted to Know About Chef But Were Afraid](https://reader030.vdocuments.site/reader030/viewer/2022041109/5f0dc6a97e708231d43c0747/html5/thumbnails/2.jpg)
Nathen Harvey
• Technical Community Manager
• Co-host Food Fight Show
• @nathenharvey
![Page 3: 5 Things You Always Wanted to Know About Chefcasitconf.org › casitconf13 › slides › Five-Things-About-Chef.pdf · 5 Things You Always Wanted to Know About Chef But Were Afraid](https://reader030.vdocuments.site/reader030/viewer/2022041109/5f0dc6a97e708231d43c0747/html5/thumbnails/3.jpg)
What Things?
• Attribute Precendence
• Encrypted Data Bags
• LWRPs
• Report & Error Handlers
• Testing Your Chef Code
• and more if there’s time...
![Page 4: 5 Things You Always Wanted to Know About Chefcasitconf.org › casitconf13 › slides › Five-Things-About-Chef.pdf · 5 Things You Always Wanted to Know About Chef But Were Afraid](https://reader030.vdocuments.site/reader030/viewer/2022041109/5f0dc6a97e708231d43c0747/html5/thumbnails/4.jpg)
Attribute Precedence
![Page 5: 5 Things You Always Wanted to Know About Chefcasitconf.org › casitconf13 › slides › Five-Things-About-Chef.pdf · 5 Things You Always Wanted to Know About Chef But Were Afraid](https://reader030.vdocuments.site/reader030/viewer/2022041109/5f0dc6a97e708231d43c0747/html5/thumbnails/5.jpg)
Attribute Data
• Attribute is a specific detail about a node
• IP Address
• Total Memory
• URL of third-party service
![Page 6: 5 Things You Always Wanted to Know About Chefcasitconf.org › casitconf13 › slides › Five-Things-About-Chef.pdf · 5 Things You Always Wanted to Know About Chef But Were Afraid](https://reader030.vdocuments.site/reader030/viewer/2022041109/5f0dc6a97e708231d43c0747/html5/thumbnails/6.jpg)
Attribute Data
• Attribute data can come from many places
• Cookbook
• Recipe
• Environment
• Role
• Data Bag
• Ohai
![Page 7: 5 Things You Always Wanted to Know About Chefcasitconf.org › casitconf13 › slides › Five-Things-About-Chef.pdf · 5 Things You Always Wanted to Know About Chef But Were Afraid](https://reader030.vdocuments.site/reader030/viewer/2022041109/5f0dc6a97e708231d43c0747/html5/thumbnails/7.jpg)
"memory": { "swap": { "cached": "0kB", "total": "4128760kB", "free": "4128760kB" }, "total": "2055676kB", "free": "1646524kB", "buffers": "35032kB", "cached": "210276kB", "active": "125336kB", "inactive": "142884kB", "dirty": "8kB", "writeback": "0kB", "anon_pages": "22976kB", "mapped": "8416kB", "slab": "121512kB", "slab_reclaimable": "41148kB", "slab_unreclaim": "80364kB", "page_tables": "1784kB", "nfs_unstable": "0kB", "bounce": "0kB", "commit_limit": "5156596kB", "committed_as": "74980kB", "vmalloc_total": "34359738367kB", "vmalloc_used": "274512kB", "vmalloc_chunk": "34359449936kB" },
Ohai! "block_device": { "ram0": { "size": "32768", "removable": "0" }, "ram1": { "size": "32768", "removable": "0" }, "ram2": { "size": "32768", "removable": "0" },
"hostname": "server-1", "fqdn": "server-1.example.com", "domain": "example.com", "network": { "interfaces": { "eth0": { "type": "eth", "number": "0", "encapsulation": "Ethernet", "addresses": { "00:0C:29:43:26:C5": { "family": "lladdr" }, "192.168.177.138": { "family": "inet", "broadcast": "192.168.177.255", "netmask": "255.255.255.0" }, "fe80::20c:29ff:fe43:26c5": { "family": "inet6", "prefixlen": "64", "scope": "Link" } },
![Page 8: 5 Things You Always Wanted to Know About Chefcasitconf.org › casitconf13 › slides › Five-Things-About-Chef.pdf · 5 Things You Always Wanted to Know About Chef But Were Afraid](https://reader030.vdocuments.site/reader030/viewer/2022041109/5f0dc6a97e708231d43c0747/html5/thumbnails/8.jpg)
Using Ohai Data
execute "load sysctl" do command "/sbin/sysctl -p" action :nothingend
bytes = node['memory']['total'].split('kB')[0].to_i * 1024 / 3pages = node['memory']['total'].split('kB')[0].to_i * 1024 / 3 / 2048
# adjust shared memory and semaphorestemplate "/etc/sysctl.conf" do source "sysctl.conf.erb" variables( :shmmax_in_bytes => bytes, :shmall_in_pages => pages ) notifies :run, "execute[load sysctl]", :immediatelyend
![Page 9: 5 Things You Always Wanted to Know About Chefcasitconf.org › casitconf13 › slides › Five-Things-About-Chef.pdf · 5 Things You Always Wanted to Know About Chef But Were Afraid](https://reader030.vdocuments.site/reader030/viewer/2022041109/5f0dc6a97e708231d43c0747/html5/thumbnails/9.jpg)
Using Ohai Data
execute "load sysctl" do command "/sbin/sysctl -p" action :nothingend
bytes = node['memory']['total'].split('kB')[0].to_i * 1024 / 3pages = node['memory']['total'].split('kB')[0].to_i * 1024 / 3 / 2048
# adjust shared memory and semaphorestemplate "/etc/sysctl.conf" do source "sysctl.conf.erb" variables( :shmmax_in_bytes => bytes, :shmall_in_pages => pages ) notifies :run, "execute[load sysctl]", :immediatelyend
![Page 10: 5 Things You Always Wanted to Know About Chefcasitconf.org › casitconf13 › slides › Five-Things-About-Chef.pdf · 5 Things You Always Wanted to Know About Chef But Were Afraid](https://reader030.vdocuments.site/reader030/viewer/2022041109/5f0dc6a97e708231d43c0747/html5/thumbnails/10.jpg)
Using Ohai Data
execute "load sysctl" do command "/sbin/sysctl -p" action :nothingend
bytes = node['memory']['total'].split('kB')[0].to_i * 1024 / 3pages = node['memory']['total'].split('kB')[0].to_i * 1024 / 3 / 2048
# adjust shared memory and semaphorestemplate "/etc/sysctl.conf" do source "sysctl.conf.erb" variables( :shmmax_in_bytes => bytes, :shmall_in_pages => pages ) notifies :run, "execute[load sysctl]", :immediatelyend
![Page 11: 5 Things You Always Wanted to Know About Chefcasitconf.org › casitconf13 › slides › Five-Things-About-Chef.pdf · 5 Things You Always Wanted to Know About Chef But Were Afraid](https://reader030.vdocuments.site/reader030/viewer/2022041109/5f0dc6a97e708231d43c0747/html5/thumbnails/11.jpg)
Environmental Data
App
PayPal
App
PayPal
Testwww.sandbox.paypal.com
Productionwww.paypal.com
![Page 12: 5 Things You Always Wanted to Know About Chefcasitconf.org › casitconf13 › slides › Five-Things-About-Chef.pdf · 5 Things You Always Wanted to Know About Chef But Were Afraid](https://reader030.vdocuments.site/reader030/viewer/2022041109/5f0dc6a97e708231d43c0747/html5/thumbnails/12.jpg)
Modeling Environmental Data
# File: environments/production.rbname "production"description "Production Environment"default_attributes "paypal" => { "hostname" => "www.paypal.com"}
# File: environments/staging.rbname "staging"description "Staging Environment"default_attributes "paypal" => { "hostname" => "www.sandbox.paypal.com"}
![Page 13: 5 Things You Always Wanted to Know About Chefcasitconf.org › casitconf13 › slides › Five-Things-About-Chef.pdf · 5 Things You Always Wanted to Know About Chef But Were Afraid](https://reader030.vdocuments.site/reader030/viewer/2022041109/5f0dc6a97e708231d43c0747/html5/thumbnails/13.jpg)
Modeling Environmental Data
# This file managed by Chef!
url: https://<%= node['paypal']['hostname'] %>/cgi-bin/webscr
![Page 14: 5 Things You Always Wanted to Know About Chefcasitconf.org › casitconf13 › slides › Five-Things-About-Chef.pdf · 5 Things You Always Wanted to Know About Chef But Were Afraid](https://reader030.vdocuments.site/reader030/viewer/2022041109/5f0dc6a97e708231d43c0747/html5/thumbnails/14.jpg)
Attribute Data
• Attribute data can come from many places
• Cookbook
• Recipe
• Environment
• Role
• Data Bag
• Ohai
![Page 15: 5 Things You Always Wanted to Know About Chefcasitconf.org › casitconf13 › slides › Five-Things-About-Chef.pdf · 5 Things You Always Wanted to Know About Chef But Were Afraid](https://reader030.vdocuments.site/reader030/viewer/2022041109/5f0dc6a97e708231d43c0747/html5/thumbnails/15.jpg)
Attribute Files
Node/Recipe
Environment Role
Default
Force Default
Normal
Override
Force Override
Automatic
1 2 3 4
5 6
7 8
9 10 12 11
13 14
15151515
When you combine precedence and merge order, you get the complete picture of node attribute setting
![Page 16: 5 Things You Always Wanted to Know About Chefcasitconf.org › casitconf13 › slides › Five-Things-About-Chef.pdf · 5 Things You Always Wanted to Know About Chef But Were Afraid](https://reader030.vdocuments.site/reader030/viewer/2022041109/5f0dc6a97e708231d43c0747/html5/thumbnails/16.jpg)
Encrypted Data Bags
![Page 17: 5 Things You Always Wanted to Know About Chefcasitconf.org › casitconf13 › slides › Five-Things-About-Chef.pdf · 5 Things You Always Wanted to Know About Chef But Were Afraid](https://reader030.vdocuments.site/reader030/viewer/2022041109/5f0dc6a97e708231d43c0747/html5/thumbnails/17.jpg)
Data Bags
• Variable data stored in JSON
• Stored on and retrieved from the Chef Server
• (also stored in your source code repository)
![Page 18: 5 Things You Always Wanted to Know About Chefcasitconf.org › casitconf13 › slides › Five-Things-About-Chef.pdf · 5 Things You Always Wanted to Know About Chef But Were Afraid](https://reader030.vdocuments.site/reader030/viewer/2022041109/5f0dc6a97e708231d43c0747/html5/thumbnails/18.jpg)
User Data Bag Item
{ "id": "nharvey", "groups": ["sysadmin"], "uid": 2001, "shell": "/bin/bash", "comment": "Nathen Harvey", "nagios": { "email": "[email protected]" }, "ssh_keys" : "ssh-rsa AB3Nza...FVsw== nharvey@opscode"}
![Page 19: 5 Things You Always Wanted to Know About Chefcasitconf.org › casitconf13 › slides › Five-Things-About-Chef.pdf · 5 Things You Always Wanted to Know About Chef But Were Afraid](https://reader030.vdocuments.site/reader030/viewer/2022041109/5f0dc6a97e708231d43c0747/html5/thumbnails/19.jpg)
Data Bag Items in a Recipe
search(:users, "*:*").each do |user_data|
user user_data['id'] do uid user_data['uid'] home user_data['home'] shell user_data['shell'] end
end
![Page 20: 5 Things You Always Wanted to Know About Chefcasitconf.org › casitconf13 › slides › Five-Things-About-Chef.pdf · 5 Things You Always Wanted to Know About Chef But Were Afraid](https://reader030.vdocuments.site/reader030/viewer/2022041109/5f0dc6a97e708231d43c0747/html5/thumbnails/20.jpg)
Data Bags
• Variable data stored in JSON
• Stored on and retrieved from the Chef Server
• (also stored in your source code repository)
![Page 21: 5 Things You Always Wanted to Know About Chefcasitconf.org › casitconf13 › slides › Five-Things-About-Chef.pdf · 5 Things You Always Wanted to Know About Chef But Were Afraid](https://reader030.vdocuments.site/reader030/viewer/2022041109/5f0dc6a97e708231d43c0747/html5/thumbnails/21.jpg)
Sensitive Data
{ "id": "database", "username": "awesome_app", "password": "super_sercet1!"}
![Page 22: 5 Things You Always Wanted to Know About Chefcasitconf.org › casitconf13 › slides › Five-Things-About-Chef.pdf · 5 Things You Always Wanted to Know About Chef But Were Afraid](https://reader030.vdocuments.site/reader030/viewer/2022041109/5f0dc6a97e708231d43c0747/html5/thumbnails/22.jpg)
Encrypt the Data
$ openssl rand -base64 512 > .chef/encrypted_data_bag_secret
$ knife data bag create credentials database \ --secret-file .chef/encrypted_data_bag_secret
![Page 23: 5 Things You Always Wanted to Know About Chefcasitconf.org › casitconf13 › slides › Five-Things-About-Chef.pdf · 5 Things You Always Wanted to Know About Chef But Were Afraid](https://reader030.vdocuments.site/reader030/viewer/2022041109/5f0dc6a97e708231d43c0747/html5/thumbnails/23.jpg)
Encrypted Data
$ knife data bag show credentials database
id: databasepassword: cipher: aes-256-cbc encrypted_data: VimII9irDvU7kYNBLiYUVGQYY0RUo9Q2xvairNGbch19aBA/6q/2lbKzHTdo mbxB
iv: 9uBvym60oN5UYF/4A9p40Q==
version: 1username: cipher: aes-256-cbc encrypted_data: N+GzLZ1nKC3K1BhPXZP8e5s19GHxh0WUIIz/sma9+Jg=
iv: Blu9+a2A1CghtFAdEPb1JQ==
version: 1
![Page 24: 5 Things You Always Wanted to Know About Chefcasitconf.org › casitconf13 › slides › Five-Things-About-Chef.pdf · 5 Things You Always Wanted to Know About Chef But Were Afraid](https://reader030.vdocuments.site/reader030/viewer/2022041109/5f0dc6a97e708231d43c0747/html5/thumbnails/24.jpg)
Use Encrypted Data in a Recipe
creds = Chef::EncryptedDataBagItem.load("credentials", "database")
template "/svr/awesome_app/config/database.yml" do variables( :username => creds['username'], :password => creds['password'] )end
![Page 25: 5 Things You Always Wanted to Know About Chefcasitconf.org › casitconf13 › slides › Five-Things-About-Chef.pdf · 5 Things You Always Wanted to Know About Chef But Were Afraid](https://reader030.vdocuments.site/reader030/viewer/2022041109/5f0dc6a97e708231d43c0747/html5/thumbnails/25.jpg)
LWRPs
![Page 26: 5 Things You Always Wanted to Know About Chefcasitconf.org › casitconf13 › slides › Five-Things-About-Chef.pdf · 5 Things You Always Wanted to Know About Chef But Were Afraid](https://reader030.vdocuments.site/reader030/viewer/2022041109/5f0dc6a97e708231d43c0747/html5/thumbnails/26.jpg)
Resources and Providers
• Chef provides a set of resources & providers
![Page 27: 5 Things You Always Wanted to Know About Chefcasitconf.org › casitconf13 › slides › Five-Things-About-Chef.pdf · 5 Things You Always Wanted to Know About Chef But Were Afraid](https://reader030.vdocuments.site/reader030/viewer/2022041109/5f0dc6a97e708231d43c0747/html5/thumbnails/27.jpg)
package "ntp" do action :installend
Resources
• Declarative specification of policy
![Page 28: 5 Things You Always Wanted to Know About Chefcasitconf.org › casitconf13 › slides › Five-Things-About-Chef.pdf · 5 Things You Always Wanted to Know About Chef But Were Afraid](https://reader030.vdocuments.site/reader030/viewer/2022041109/5f0dc6a97e708231d43c0747/html5/thumbnails/28.jpg)
def action_install # If we specified a version, and it's not the current version, move to the specified version if !@new_resource.version.nil? && !(target_version_already_installed?) install_version = @new_resource.version # If it's not installed at all, install it elsif @current_resource.version.nil? install_version = candidate_version else Chef::Log.debug("#{@new_resource} is already installed - nothing to do") return end
...
Providers
• Take steps to bring resource in to compliance with policy
![Page 29: 5 Things You Always Wanted to Know About Chefcasitconf.org › casitconf13 › slides › Five-Things-About-Chef.pdf · 5 Things You Always Wanted to Know About Chef But Were Afraid](https://reader030.vdocuments.site/reader030/viewer/2022041109/5f0dc6a97e708231d43c0747/html5/thumbnails/29.jpg)
Resources and Providers
• Resources
• Declarative interface
• Providers
• Implementation
![Page 30: 5 Things You Always Wanted to Know About Chefcasitconf.org › casitconf13 › slides › Five-Things-About-Chef.pdf · 5 Things You Always Wanted to Know About Chef But Were Afraid](https://reader030.vdocuments.site/reader030/viewer/2022041109/5f0dc6a97e708231d43c0747/html5/thumbnails/30.jpg)
Lightweight Resource and Provider
• Lightweight Resource and Provider
• LWRP
• Custom resource and provider
![Page 31: 5 Things You Always Wanted to Know About Chefcasitconf.org › casitconf13 › slides › Five-Things-About-Chef.pdf · 5 Things You Always Wanted to Know About Chef But Were Afraid](https://reader030.vdocuments.site/reader030/viewer/2022041109/5f0dc6a97e708231d43c0747/html5/thumbnails/31.jpg)
Recipe Code - Before LWRP
file "/etc/profile.d/myrailsapp.sh" do mode "0644" content "alias current='cd /svr/myrailsapp/current'"end
file "/etc/profile.d/h.sh" do mode "0644" content "alias h='cd ~/'"end
![Page 32: 5 Things You Always Wanted to Know About Chefcasitconf.org › casitconf13 › slides › Five-Things-About-Chef.pdf · 5 Things You Always Wanted to Know About Chef But Were Afraid](https://reader030.vdocuments.site/reader030/viewer/2022041109/5f0dc6a97e708231d43c0747/html5/thumbnails/32.jpg)
Recipe Code - After LWRP
magic_shell_alias "current" do command "cd /svr/myrailsapp/current"end
magic_shell_alias "h" do command "cd ~/"end
![Page 33: 5 Things You Always Wanted to Know About Chefcasitconf.org › casitconf13 › slides › Five-Things-About-Chef.pdf · 5 Things You Always Wanted to Know About Chef But Were Afraid](https://reader030.vdocuments.site/reader030/viewer/2022041109/5f0dc6a97e708231d43c0747/html5/thumbnails/33.jpg)
Custom Resource
actions :add, :remove
default_action :add
attribute :alias_name, :kind_of => String, :name_attribute => trueattribute :command, :kind_of => String, :default => :add
![Page 34: 5 Things You Always Wanted to Know About Chefcasitconf.org › casitconf13 › slides › Five-Things-About-Chef.pdf · 5 Things You Always Wanted to Know About Chef But Were Afraid](https://reader030.vdocuments.site/reader030/viewer/2022041109/5f0dc6a97e708231d43c0747/html5/thumbnails/34.jpg)
Custom Provider
action :add do command_name = new_resource.alias_name.gsub(/ /,"_") if !new_resource.command.nil? Chef::Log.info("Adding #{command_name}.sh to /etc/profile.d/") file_contents = "# This alias was generated by Chef for #{node["fqdn"]}\n" file_contents += "alias #{command_name}='#{new_resource.command}'" resource = file "/etc/profile.d/#{command_name}.sh" do owner "root" group "root" mode "0755" content file_contents action :nothing end resource.run_action(:create) new_resource.updated_by_last_action(true) if resource.updated_by_last_action? endend
![Page 35: 5 Things You Always Wanted to Know About Chefcasitconf.org › casitconf13 › slides › Five-Things-About-Chef.pdf · 5 Things You Always Wanted to Know About Chef But Were Afraid](https://reader030.vdocuments.site/reader030/viewer/2022041109/5f0dc6a97e708231d43c0747/html5/thumbnails/35.jpg)
LWRP
• Custom Resource and Provider
• Interface and Implementation
• Encapsulate common functionality
• http://ckbk.it/magic_shell
![Page 36: 5 Things You Always Wanted to Know About Chefcasitconf.org › casitconf13 › slides › Five-Things-About-Chef.pdf · 5 Things You Always Wanted to Know About Chef But Were Afraid](https://reader030.vdocuments.site/reader030/viewer/2022041109/5f0dc6a97e708231d43c0747/html5/thumbnails/36.jpg)
Exception & Report Handlers
![Page 37: 5 Things You Always Wanted to Know About Chefcasitconf.org › casitconf13 › slides › Five-Things-About-Chef.pdf · 5 Things You Always Wanted to Know About Chef But Were Afraid](https://reader030.vdocuments.site/reader030/viewer/2022041109/5f0dc6a97e708231d43c0747/html5/thumbnails/37.jpg)
Exception & Report Handlers
• Run custom code when chef-client run starts, ends, fails, or succeeds
• Use cases
• Notify when a chef-client run fails
• Gather data about chef-client runs
![Page 38: 5 Things You Always Wanted to Know About Chefcasitconf.org › casitconf13 › slides › Five-Things-About-Chef.pdf · 5 Things You Always Wanted to Know About Chef But Were Afraid](https://reader030.vdocuments.site/reader030/viewer/2022041109/5f0dc6a97e708231d43c0747/html5/thumbnails/38.jpg)
Exception & Report Handlers
• success? / failed?
• exception
• all_resources
• updated_resources
• elapsed_time
• ...and more!
![Page 39: 5 Things You Always Wanted to Know About Chefcasitconf.org › casitconf13 › slides › Five-Things-About-Chef.pdf · 5 Things You Always Wanted to Know About Chef But Were Afraid](https://reader030.vdocuments.site/reader030/viewer/2022041109/5f0dc6a97e708231d43c0747/html5/thumbnails/39.jpg)
Handlers from the Community
• Airbrake exceptions
• Campfire handler
• chef-handler-graphite
• Mail report handler
• ...and more
![Page 40: 5 Things You Always Wanted to Know About Chefcasitconf.org › casitconf13 › slides › Five-Things-About-Chef.pdf · 5 Things You Always Wanted to Know About Chef But Were Afraid](https://reader030.vdocuments.site/reader030/viewer/2022041109/5f0dc6a97e708231d43c0747/html5/thumbnails/40.jpg)
Testing Your Chef Code
![Page 41: 5 Things You Always Wanted to Know About Chefcasitconf.org › casitconf13 › slides › Five-Things-About-Chef.pdf · 5 Things You Always Wanted to Know About Chef But Were Afraid](https://reader030.vdocuments.site/reader030/viewer/2022041109/5f0dc6a97e708231d43c0747/html5/thumbnails/41.jpg)
Why test?
![Page 42: 5 Things You Always Wanted to Know About Chefcasitconf.org › casitconf13 › slides › Five-Things-About-Chef.pdf · 5 Things You Always Wanted to Know About Chef But Were Afraid](https://reader030.vdocuments.site/reader030/viewer/2022041109/5f0dc6a97e708231d43c0747/html5/thumbnails/42.jpg)
Testing Tools
• knife cookbook test
![Page 43: 5 Things You Always Wanted to Know About Chefcasitconf.org › casitconf13 › slides › Five-Things-About-Chef.pdf · 5 Things You Always Wanted to Know About Chef But Were Afraid](https://reader030.vdocuments.site/reader030/viewer/2022041109/5f0dc6a97e708231d43c0747/html5/thumbnails/43.jpg)
knife cookbook test
$ knife cookbook test websitechecking websiteRunning syntax check on websiteValidating ruby filesValidating templates
![Page 44: 5 Things You Always Wanted to Know About Chefcasitconf.org › casitconf13 › slides › Five-Things-About-Chef.pdf · 5 Things You Always Wanted to Know About Chef But Were Afraid](https://reader030.vdocuments.site/reader030/viewer/2022041109/5f0dc6a97e708231d43c0747/html5/thumbnails/44.jpg)
Testing Tools
• knife cookbook test
• foodcritic
![Page 45: 5 Things You Always Wanted to Know About Chefcasitconf.org › casitconf13 › slides › Five-Things-About-Chef.pdf · 5 Things You Always Wanted to Know About Chef But Were Afraid](https://reader030.vdocuments.site/reader030/viewer/2022041109/5f0dc6a97e708231d43c0747/html5/thumbnails/45.jpg)
Foodcritic
• A lint tool for your Opscode Chef cookbooks
• Flag problems in your Chef cookbooks that will cause Chef to blow up when you attempt to converge
• Encourage discussion within the Chef community on the more subjective stuff - what does a good cookbook look like?
![Page 46: 5 Things You Always Wanted to Know About Chefcasitconf.org › casitconf13 › slides › Five-Things-About-Chef.pdf · 5 Things You Always Wanted to Know About Chef But Were Afraid](https://reader030.vdocuments.site/reader030/viewer/2022041109/5f0dc6a97e708231d43c0747/html5/thumbnails/46.jpg)
Foodcritic
$ foodcritic cookbooks/website
FC006: Mode should be quoted or fully specified when setting file permissions: cookbooks/website/recipes/default.rb:11
FC008: Generated cookbook metadata needs updating: cookbooks/website/metadata.rb:2
FC008: Generated cookbook metadata needs updating: cookbooks/website/metadata.rb:3
![Page 47: 5 Things You Always Wanted to Know About Chefcasitconf.org › casitconf13 › slides › Five-Things-About-Chef.pdf · 5 Things You Always Wanted to Know About Chef But Were Afraid](https://reader030.vdocuments.site/reader030/viewer/2022041109/5f0dc6a97e708231d43c0747/html5/thumbnails/47.jpg)
Testing Tools
• knife cookbook test
• foodcritic
• chefspec
![Page 48: 5 Things You Always Wanted to Know About Chefcasitconf.org › casitconf13 › slides › Five-Things-About-Chef.pdf · 5 Things You Always Wanted to Know About Chef But Were Afraid](https://reader030.vdocuments.site/reader030/viewer/2022041109/5f0dc6a97e708231d43c0747/html5/thumbnails/48.jpg)
Chefspec
require 'chefspec'
describe 'website::default' do chef_run = ChefSpec::ChefRunner.new chef_run.converge "website::default"
it "should install apache package" do chef_run.should install_package "apache2" end
it "should create a home page" do chef_run.should create_file "/var/www/index.html" end
![Page 49: 5 Things You Always Wanted to Know About Chefcasitconf.org › casitconf13 › slides › Five-Things-About-Chef.pdf · 5 Things You Always Wanted to Know About Chef But Were Afraid](https://reader030.vdocuments.site/reader030/viewer/2022041109/5f0dc6a97e708231d43c0747/html5/thumbnails/49.jpg)
Testing Tools
• knife cookbook test
• foodcritic
• chefspec
• Minitest and the Minitest Chef Handler
![Page 50: 5 Things You Always Wanted to Know About Chefcasitconf.org › casitconf13 › slides › Five-Things-About-Chef.pdf · 5 Things You Always Wanted to Know About Chef But Were Afraid](https://reader030.vdocuments.site/reader030/viewer/2022041109/5f0dc6a97e708231d43c0747/html5/thumbnails/50.jpg)
minitest
class TestWebsite < MiniTest::Chef::TestCase include MiniTest::Chef::Assertions include MiniTest::Chef::Context include MiniTest::Chef::Resources
def test_succeed assert run_status.success? end def test_that_the_package_installed package("apache2").must_be_installed end
def test_that_the_service_is_running service("apache2").must_be_running end
![Page 51: 5 Things You Always Wanted to Know About Chefcasitconf.org › casitconf13 › slides › Five-Things-About-Chef.pdf · 5 Things You Always Wanted to Know About Chef But Were Afraid](https://reader030.vdocuments.site/reader030/viewer/2022041109/5f0dc6a97e708231d43c0747/html5/thumbnails/51.jpg)
minitest-handler
$ vagrant provision
[2013-02-01T06:43:34+00:00] INFO: Running report handlersRun options: -v --seed 12405# Running tests:TestWebsite#test_succeed =
...
Finished tests in 0.098367s, 60.9959 tests/s, 60.9959 assertions/s.
6 tests, 6 assertions, 0 failures, 0 errors, 0 skips
[2013-02-01T06:43:34+00:00] INFO: Report handlers complete
![Page 52: 5 Things You Always Wanted to Know About Chefcasitconf.org › casitconf13 › slides › Five-Things-About-Chef.pdf · 5 Things You Always Wanted to Know About Chef But Were Afraid](https://reader030.vdocuments.site/reader030/viewer/2022041109/5f0dc6a97e708231d43c0747/html5/thumbnails/52.jpg)
Testing Tools
• knife cookbook test
• foodcritic
• chefspec
• Minitest and the Minitest Chef Handler
• why-run
![Page 53: 5 Things You Always Wanted to Know About Chefcasitconf.org › casitconf13 › slides › Five-Things-About-Chef.pdf · 5 Things You Always Wanted to Know About Chef But Were Afraid](https://reader030.vdocuments.site/reader030/viewer/2022041109/5f0dc6a97e708231d43c0747/html5/thumbnails/53.jpg)
Why Run
$ chef-client --why-runStarting Chef Client, version 11.4.0...Converging 3 resources * package[apache2] action install - Would install version 2.2.22-1ubuntu1 of package apache2 * template[/var/www/index.html] action create * Parent directory /var/www does not exist. * Assuming directory /var/www would have been created - Would create template[/var/www/index.html] * service[apache2] action start - Would start service service[apache2] * service[apache2] action enable - Would enable service service[apache2]
WARN: In whyrun mode, so NOT performing node save.Chef Client finished, 4 resources would have been updated
![Page 54: 5 Things You Always Wanted to Know About Chefcasitconf.org › casitconf13 › slides › Five-Things-About-Chef.pdf · 5 Things You Always Wanted to Know About Chef But Were Afraid](https://reader030.vdocuments.site/reader030/viewer/2022041109/5f0dc6a97e708231d43c0747/html5/thumbnails/54.jpg)
Why Run
• Promises, Lies, and Dry-Run Mode
• http://bit.ly/guessrun
![Page 55: 5 Things You Always Wanted to Know About Chefcasitconf.org › casitconf13 › slides › Five-Things-About-Chef.pdf · 5 Things You Always Wanted to Know About Chef But Were Afraid](https://reader030.vdocuments.site/reader030/viewer/2022041109/5f0dc6a97e708231d43c0747/html5/thumbnails/55.jpg)
Testing Tools
• knife cookbook test - Verify ruby syntax
• Foodcritic - Cookbook linter
• Chefspec - Unit testing recipes
• Fauxhai - Mock all the things
• Minitest Chef Handler - post-converge tests
• Why-run - Best guess
![Page 56: 5 Things You Always Wanted to Know About Chefcasitconf.org › casitconf13 › slides › Five-Things-About-Chef.pdf · 5 Things You Always Wanted to Know About Chef But Were Afraid](https://reader030.vdocuments.site/reader030/viewer/2022041109/5f0dc6a97e708231d43c0747/html5/thumbnails/56.jpg)
Moar Testing Tools
• Vagrant - Local development and testing
• Test Kitchen - Cross-platform testing
• Cucumber Chef - acceptance & integration testing
![Page 57: 5 Things You Always Wanted to Know About Chefcasitconf.org › casitconf13 › slides › Five-Things-About-Chef.pdf · 5 Things You Always Wanted to Know About Chef But Were Afraid](https://reader030.vdocuments.site/reader030/viewer/2022041109/5f0dc6a97e708231d43c0747/html5/thumbnails/57.jpg)
Bonus Round
![Page 58: 5 Things You Always Wanted to Know About Chefcasitconf.org › casitconf13 › slides › Five-Things-About-Chef.pdf · 5 Things You Always Wanted to Know About Chef But Were Afraid](https://reader030.vdocuments.site/reader030/viewer/2022041109/5f0dc6a97e708231d43c0747/html5/thumbnails/58.jpg)
What else do you want to ask?
• Using search
• Gradually rolling out cookbook changes
• What’s new in Chef 11?
• Global Gotchas!
• Learning Chef
• Chef on Windows
• But I don’t know ruby
• Chef vs. ...
![Page 59: 5 Things You Always Wanted to Know About Chefcasitconf.org › casitconf13 › slides › Five-Things-About-Chef.pdf · 5 Things You Always Wanted to Know About Chef But Were Afraid](https://reader030.vdocuments.site/reader030/viewer/2022041109/5f0dc6a97e708231d43c0747/html5/thumbnails/59.jpg)
Search
![Page 60: 5 Things You Always Wanted to Know About Chefcasitconf.org › casitconf13 › slides › Five-Things-About-Chef.pdf · 5 Things You Always Wanted to Know About Chef But Were Afraid](https://reader030.vdocuments.site/reader030/viewer/2022041109/5f0dc6a97e708231d43c0747/html5/thumbnails/60.jpg)
Search
• What application servers should be included in my load balancer configuration?
• What host groups should I include in my nagios config?
![Page 61: 5 Things You Always Wanted to Know About Chefcasitconf.org › casitconf13 › slides › Five-Things-About-Chef.pdf · 5 Things You Always Wanted to Know About Chef But Were Afraid](https://reader030.vdocuments.site/reader030/viewer/2022041109/5f0dc6a97e708231d43c0747/html5/thumbnails/61.jpg)
What else do you want to ask?
• Using search
• Gradually rolling out cookbook changes
• What’s new in Chef 11?
• Global Gotchas!
• Learning Chef
• Chef on Windows
• But I don’t know ruby
• Chef vs. ...
![Page 62: 5 Things You Always Wanted to Know About Chefcasitconf.org › casitconf13 › slides › Five-Things-About-Chef.pdf · 5 Things You Always Wanted to Know About Chef But Were Afraid](https://reader030.vdocuments.site/reader030/viewer/2022041109/5f0dc6a97e708231d43c0747/html5/thumbnails/62.jpg)
Graduating Cookbooks Through Environments
![Page 63: 5 Things You Always Wanted to Know About Chefcasitconf.org › casitconf13 › slides › Five-Things-About-Chef.pdf · 5 Things You Always Wanted to Know About Chef But Were Afraid](https://reader030.vdocuments.site/reader030/viewer/2022041109/5f0dc6a97e708231d43c0747/html5/thumbnails/63.jpg)
Environments
• http://docs.opscode.com/essentials_environments.html
• Pin cookbook versions to specific environments
![Page 64: 5 Things You Always Wanted to Know About Chefcasitconf.org › casitconf13 › slides › Five-Things-About-Chef.pdf · 5 Things You Always Wanted to Know About Chef But Were Afraid](https://reader030.vdocuments.site/reader030/viewer/2022041109/5f0dc6a97e708231d43c0747/html5/thumbnails/64.jpg)
What else do you want to ask?
• Using search
• Gradually rolling out cookbook changes
• What’s new in Chef 11?
• Global Gotchas!
• Learning Chef
• Chef on Windows
• But I don’t know ruby
• Chef vs. ...
![Page 65: 5 Things You Always Wanted to Know About Chefcasitconf.org › casitconf13 › slides › Five-Things-About-Chef.pdf · 5 Things You Always Wanted to Know About Chef But Were Afraid](https://reader030.vdocuments.site/reader030/viewer/2022041109/5f0dc6a97e708231d43c0747/html5/thumbnails/65.jpg)
Chef 11
![Page 66: 5 Things You Always Wanted to Know About Chefcasitconf.org › casitconf13 › slides › Five-Things-About-Chef.pdf · 5 Things You Always Wanted to Know About Chef But Were Afraid](https://reader030.vdocuments.site/reader030/viewer/2022041109/5f0dc6a97e708231d43c0747/html5/thumbnails/66.jpg)
Chef 11
• Full API server re-write in Erlang
• Omnibus Chef Server Install
• chef-apply
• partial serach
• partials in tempaltes
• Commercial Support
![Page 67: 5 Things You Always Wanted to Know About Chefcasitconf.org › casitconf13 › slides › Five-Things-About-Chef.pdf · 5 Things You Always Wanted to Know About Chef But Were Afraid](https://reader030.vdocuments.site/reader030/viewer/2022041109/5f0dc6a97e708231d43c0747/html5/thumbnails/67.jpg)
What else do you want to ask?
• Using search
• Gradually rolling out cookbook changes
• What’s new in Chef 11?
• Global Gotchas!
• Learning Chef
• Chef on Windows
• But I don’t know ruby
• Chef vs. ...
![Page 68: 5 Things You Always Wanted to Know About Chefcasitconf.org › casitconf13 › slides › Five-Things-About-Chef.pdf · 5 Things You Always Wanted to Know About Chef But Were Afraid](https://reader030.vdocuments.site/reader030/viewer/2022041109/5f0dc6a97e708231d43c0747/html5/thumbnails/68.jpg)
GLOBAL Gotchas
![Page 69: 5 Things You Always Wanted to Know About Chefcasitconf.org › casitconf13 › slides › Five-Things-About-Chef.pdf · 5 Things You Always Wanted to Know About Chef But Were Afraid](https://reader030.vdocuments.site/reader030/viewer/2022041109/5f0dc6a97e708231d43c0747/html5/thumbnails/69.jpg)
GLOBAL Gotchas
• Roles
• Data Bags
• Search
![Page 70: 5 Things You Always Wanted to Know About Chefcasitconf.org › casitconf13 › slides › Five-Things-About-Chef.pdf · 5 Things You Always Wanted to Know About Chef But Were Afraid](https://reader030.vdocuments.site/reader030/viewer/2022041109/5f0dc6a97e708231d43c0747/html5/thumbnails/70.jpg)
What else do you want to ask?
• Using search
• Gradually rolling out cookbook changes
• What’s new in Chef 11?
• Global Gotchas!
• Learning Chef
• Chef on Windows
• But I don’t know ruby
• Chef vs. ...
![Page 71: 5 Things You Always Wanted to Know About Chefcasitconf.org › casitconf13 › slides › Five-Things-About-Chef.pdf · 5 Things You Always Wanted to Know About Chef But Were Afraid](https://reader030.vdocuments.site/reader030/viewer/2022041109/5f0dc6a97e708231d43c0747/html5/thumbnails/71.jpg)
Learning Chef
![Page 72: 5 Things You Always Wanted to Know About Chefcasitconf.org › casitconf13 › slides › Five-Things-About-Chef.pdf · 5 Things You Always Wanted to Know About Chef But Were Afraid](https://reader030.vdocuments.site/reader030/viewer/2022041109/5f0dc6a97e708231d43c0747/html5/thumbnails/72.jpg)
Resources
• Hosted Chef
• http://learnchef.com
• http://docs.opscode.com
• #chef on Freenode IRC
![Page 73: 5 Things You Always Wanted to Know About Chefcasitconf.org › casitconf13 › slides › Five-Things-About-Chef.pdf · 5 Things You Always Wanted to Know About Chef But Were Afraid](https://reader030.vdocuments.site/reader030/viewer/2022041109/5f0dc6a97e708231d43c0747/html5/thumbnails/73.jpg)
What else do you want to ask?
• Using search
• Gradually rolling out cookbook changes
• What’s new in Chef 11?
• Global Gotchas!
• Learning Chef
• Chef on Windows
• But I don’t know ruby
• Chef vs. ...
![Page 74: 5 Things You Always Wanted to Know About Chefcasitconf.org › casitconf13 › slides › Five-Things-About-Chef.pdf · 5 Things You Always Wanted to Know About Chef But Were Afraid](https://reader030.vdocuments.site/reader030/viewer/2022041109/5f0dc6a97e708231d43c0747/html5/thumbnails/74.jpg)
Windows
![Page 75: 5 Things You Always Wanted to Know About Chefcasitconf.org › casitconf13 › slides › Five-Things-About-Chef.pdf · 5 Things You Always Wanted to Know About Chef But Were Afraid](https://reader030.vdocuments.site/reader030/viewer/2022041109/5f0dc6a97e708231d43c0747/html5/thumbnails/75.jpg)
Chef on Windows?
That’s the band Yes
Yes, Chef manages Windows, too!
![Page 76: 5 Things You Always Wanted to Know About Chefcasitconf.org › casitconf13 › slides › Five-Things-About-Chef.pdf · 5 Things You Always Wanted to Know About Chef But Were Afraid](https://reader030.vdocuments.site/reader030/viewer/2022041109/5f0dc6a97e708231d43c0747/html5/thumbnails/76.jpg)
What else do you want to ask?
• Using search
• Gradually rolling out cookbook changes
• What’s new in Chef 11?
• Global Gotchas!
• Learning Chef
• Chef on Windows
• But I don’t know ruby
• Chef vs. ...
![Page 77: 5 Things You Always Wanted to Know About Chefcasitconf.org › casitconf13 › slides › Five-Things-About-Chef.pdf · 5 Things You Always Wanted to Know About Chef But Were Afraid](https://reader030.vdocuments.site/reader030/viewer/2022041109/5f0dc6a97e708231d43c0747/html5/thumbnails/77.jpg)
Ruby
![Page 78: 5 Things You Always Wanted to Know About Chefcasitconf.org › casitconf13 › slides › Five-Things-About-Chef.pdf · 5 Things You Always Wanted to Know About Chef But Were Afraid](https://reader030.vdocuments.site/reader030/viewer/2022041109/5f0dc6a97e708231d43c0747/html5/thumbnails/78.jpg)
Ruby
%w{htop dstat strace sysstat gdb tmux tshark}.each do |tool_package|
package tool_packageend
![Page 79: 5 Things You Always Wanted to Know About Chefcasitconf.org › casitconf13 › slides › Five-Things-About-Chef.pdf · 5 Things You Always Wanted to Know About Chef But Were Afraid](https://reader030.vdocuments.site/reader030/viewer/2022041109/5f0dc6a97e708231d43c0747/html5/thumbnails/79.jpg)
Ruby
case platformwhen "redhat", "centos", "scientific", "fedora", "suse", "amazon", "oracle" default['apache']['package'] = "httpd"when "debian", "ubuntu" default['apache']['package'] = "apache2"when "arch" default['apache']['package'] = "apache"when "freebsd" default['apache']['package'] = "apache22"end
package node['apache']['package'] do action :installend
![Page 80: 5 Things You Always Wanted to Know About Chefcasitconf.org › casitconf13 › slides › Five-Things-About-Chef.pdf · 5 Things You Always Wanted to Know About Chef But Were Afraid](https://reader030.vdocuments.site/reader030/viewer/2022041109/5f0dc6a97e708231d43c0747/html5/thumbnails/80.jpg)
Ruby for Chef
• http://docs.opscode.com/just_enough_ruby_for_chef.html
• http://blog.loftninjas.org/2011/02/16/the-power-of-chef-and-ruby/
![Page 81: 5 Things You Always Wanted to Know About Chefcasitconf.org › casitconf13 › slides › Five-Things-About-Chef.pdf · 5 Things You Always Wanted to Know About Chef But Were Afraid](https://reader030.vdocuments.site/reader030/viewer/2022041109/5f0dc6a97e708231d43c0747/html5/thumbnails/81.jpg)
What else do you want to ask?
• Using search
• Gradually rolling out cookbook changes
• What’s new in Chef 11?
• Global Gotchas!
• Learning Chef
• Chef on Windows
• But I don’t know ruby
• Chef vs. ...
![Page 82: 5 Things You Always Wanted to Know About Chefcasitconf.org › casitconf13 › slides › Five-Things-About-Chef.pdf · 5 Things You Always Wanted to Know About Chef But Were Afraid](https://reader030.vdocuments.site/reader030/viewer/2022041109/5f0dc6a97e708231d43c0747/html5/thumbnails/82.jpg)
Chef vs.
![Page 83: 5 Things You Always Wanted to Know About Chefcasitconf.org › casitconf13 › slides › Five-Things-About-Chef.pdf · 5 Things You Always Wanted to Know About Chef But Were Afraid](https://reader030.vdocuments.site/reader030/viewer/2022041109/5f0dc6a97e708231d43c0747/html5/thumbnails/83.jpg)
![Page 84: 5 Things You Always Wanted to Know About Chefcasitconf.org › casitconf13 › slides › Five-Things-About-Chef.pdf · 5 Things You Always Wanted to Know About Chef But Were Afraid](https://reader030.vdocuments.site/reader030/viewer/2022041109/5f0dc6a97e708231d43c0747/html5/thumbnails/84.jpg)
What else do you want to ask?
• Using search
• Gradually rolling out cookbook changes
• What’s new in Chef 11?
• Global Gotchas!
• Learning Chef
• Chef on Windows
• But I don’t know ruby
• Chef vs. ...
![Page 85: 5 Things You Always Wanted to Know About Chefcasitconf.org › casitconf13 › slides › Five-Things-About-Chef.pdf · 5 Things You Always Wanted to Know About Chef But Were Afraid](https://reader030.vdocuments.site/reader030/viewer/2022041109/5f0dc6a97e708231d43c0747/html5/thumbnails/85.jpg)
5 or more Things You Always Wanted to Know About Chef
Thank You!
Nathen [email protected]
@nathenharvey