SlideShare a Scribd company logo
Chef-Zero & Local Mode
Michael Goetz
Automation Consulting Engineer, Chef
mpgoetz@getchef.com

v1.2.3
Back in my day…
• Getting started with
Chef involved a lot of
setup
• Configure
workstation
• Configure Chef
server
• Bootstrap node
Chef-Client with Chef Server
• Chef-client
communicates with
Chef server
• Node object stored on
Chef server
• Cookbooks, roles,
environments, etc.
uploaded from
workstation with knife

chef-client
Chef-Solo
• Runs locally on node
• Cookbooks, data bags,
roles, environments
stored on disk
• Does not support
• Node storage
• Search indexes
• Persistent attributes

chef-solo -c ~/solo.rb -j ~/node.json
Chef-Zero
• Chef 11+ compliant
• Easy to run, fast to start
• Runs in memory
• Great for mocking a Chef
server locally
!

• Not intended for production use
• No input validation,
authentication, authorization
• Data does not persist between
restarts

http://www.nevinmartell.com/wp-content/uploads/2012/10/always_trust_a_skinny_chef.jpg
But does it blend?
• Search
• Node data
• Client data
• Cookbooks
• Data bags
• Roles
• Environments
Using Chef-Zero
• Install chef-zero gem
• $ gem install chef-zero
• Start chef-zero server (defaults to 127.0.0.1:8889)
• $ chef-zero
• Setup knife.rb with server details
• chef_server_url 'http://127.0.0.1:8889'
node_name
client_key

'tastesgreat'
‘dummy_key.pem'
Great… So now what?
• Vagrant integration with vagrant-chef-zero
• https://github.com/andrewgross/vagrant-chef-zero
• Allows testing of searches, node data without
connecting to a “real” chef server
• Mock cluster node data
• Validate data bag queries
• Automated testing with Test-Kitchen
• http://kitchen.ci/
• provisioner
name: chef_zero
Going native with local mode

http://www.prosperapartners.org/wp-content/uploads/2012/07/i-am-a-localist.png

• Harness the power of chef-zero
within chef-client
• chef-client -z & knife -z
• Loads files from current directory
• /cookbooks
• /nodes
• /roles
• /environments
• Writes data changes back to
local file system
• knife works too!
Setup Data Bag & Recipe
• Create default recipe
• Search for node data,
printed out to “/tmp/
zerofiles”
!

• Setup data bag
structure
• Print content of data
bag out to “/tmp/fluff”

cookbooks/zero/recipes/default.rb
a = search(:node, "*:*")!
b = data_bag_item("zero", "fluff")!
!
file "/tmp/zerofiles" do!
content a[0].to_s!
end!
!
file "/tmp/fluff" do!
content b.to_s!
end

data_bags/zero/fluff
{!
"id": "fluff",!
"clouds": "Are fluffy"!
}
Converge!
$ chef-client -z -o zero
[2013-12-10T23:53:32-06:00] WARN: No config file found or specified on command line, not loading.!
Starting Chef Client, version 11.8.2!
[2013-12-10T23:53:36-06:00] WARN: Run List override has been provided.!
[2013-12-10T23:53:36-06:00] WARN: Original Run List: [recipe[zero]]!
[2013-12-10T23:53:36-06:00] WARN: Overridden Run List: [recipe[zero]]!
resolving cookbooks for run list: ["zero"]!
Synchronizing Cookbooks:!
- zero!
Compiling Cookbooks...!
Converging 2 resources!
Recipe: zero::default!
* file[/tmp/zerofiles] action create!
- create new file /tmp/zerofiles!
- update content in file /tmp/zerofiles from none to 0a038a!
--- /tmp/zerofiles
2013-12-10 23:53:36.368059768 -0600!
+++ /tmp/.zerofiles20131210-6903-10cvytu
2013-12-10 23:53:36.368059768 -0600!
@@ -1 +1,2 @@!
+node[localhost]!
* file[/tmp/fluff] action create!
- create new file /tmp/fluff!
- update content in file /tmp/fluff from none to d46bab!
--- /tmp/fluff 2013-12-10 23:53:36.372059683 -0600!
+++ /tmp/.fluff20131210-6903-1l3i1h
2013-12-10 23:53:36.372059683 -0600!
@@ -1 +1,2 @@!
+data_bag_item[fluff]!
Chef Client finished, 2 resources updated
Learn more
• From Zero to Chef in 8.5 Seconds
• http://www.getchef.com/blog/2013/10/31/chef-client-z-fromzero-to-chef-in-8-5-seconds/
!

• Chef Docs Site
• http://docs.opscode.com/release_notes.html#chef-client-localmode
!

• Chef-Zero on GitHub
• https://github.com/opscode/chef-zero

More Related Content

Chef-Zero & Local Mode

  • 1. Chef-Zero & Local Mode Michael Goetz Automation Consulting Engineer, Chef [email protected] v1.2.3
  • 2. Back in my day… • Getting started with Chef involved a lot of setup • Configure workstation • Configure Chef server • Bootstrap node
  • 3. Chef-Client with Chef Server • Chef-client communicates with Chef server • Node object stored on Chef server • Cookbooks, roles, environments, etc. uploaded from workstation with knife chef-client
  • 4. Chef-Solo • Runs locally on node • Cookbooks, data bags, roles, environments stored on disk • Does not support • Node storage • Search indexes • Persistent attributes chef-solo -c ~/solo.rb -j ~/node.json
  • 5. Chef-Zero • Chef 11+ compliant • Easy to run, fast to start • Runs in memory • Great for mocking a Chef server locally ! • Not intended for production use • No input validation, authentication, authorization • Data does not persist between restarts http://www.nevinmartell.com/wp-content/uploads/2012/10/always_trust_a_skinny_chef.jpg
  • 6. But does it blend? • Search • Node data • Client data • Cookbooks • Data bags • Roles • Environments
  • 7. Using Chef-Zero • Install chef-zero gem • $ gem install chef-zero • Start chef-zero server (defaults to 127.0.0.1:8889) • $ chef-zero • Setup knife.rb with server details • chef_server_url 'http://127.0.0.1:8889' node_name client_key 'tastesgreat' ‘dummy_key.pem'
  • 8. Great… So now what? • Vagrant integration with vagrant-chef-zero • https://github.com/andrewgross/vagrant-chef-zero • Allows testing of searches, node data without connecting to a “real” chef server • Mock cluster node data • Validate data bag queries • Automated testing with Test-Kitchen • http://kitchen.ci/ • provisioner name: chef_zero
  • 9. Going native with local mode http://www.prosperapartners.org/wp-content/uploads/2012/07/i-am-a-localist.png • Harness the power of chef-zero within chef-client • chef-client -z & knife -z • Loads files from current directory • /cookbooks • /nodes • /roles • /environments • Writes data changes back to local file system • knife works too!
  • 10. Setup Data Bag & Recipe • Create default recipe • Search for node data, printed out to “/tmp/ zerofiles” ! • Setup data bag structure • Print content of data bag out to “/tmp/fluff” cookbooks/zero/recipes/default.rb a = search(:node, "*:*")! b = data_bag_item("zero", "fluff")! ! file "/tmp/zerofiles" do! content a[0].to_s! end! ! file "/tmp/fluff" do! content b.to_s! end data_bags/zero/fluff {! "id": "fluff",! "clouds": "Are fluffy"! }
  • 11. Converge! $ chef-client -z -o zero [2013-12-10T23:53:32-06:00] WARN: No config file found or specified on command line, not loading.! Starting Chef Client, version 11.8.2! [2013-12-10T23:53:36-06:00] WARN: Run List override has been provided.! [2013-12-10T23:53:36-06:00] WARN: Original Run List: [recipe[zero]]! [2013-12-10T23:53:36-06:00] WARN: Overridden Run List: [recipe[zero]]! resolving cookbooks for run list: ["zero"]! Synchronizing Cookbooks:! - zero! Compiling Cookbooks...! Converging 2 resources! Recipe: zero::default! * file[/tmp/zerofiles] action create! - create new file /tmp/zerofiles! - update content in file /tmp/zerofiles from none to 0a038a! --- /tmp/zerofiles 2013-12-10 23:53:36.368059768 -0600! +++ /tmp/.zerofiles20131210-6903-10cvytu 2013-12-10 23:53:36.368059768 -0600! @@ -1 +1,2 @@! +node[localhost]! * file[/tmp/fluff] action create! - create new file /tmp/fluff! - update content in file /tmp/fluff from none to d46bab! --- /tmp/fluff 2013-12-10 23:53:36.372059683 -0600! +++ /tmp/.fluff20131210-6903-1l3i1h 2013-12-10 23:53:36.372059683 -0600! @@ -1 +1,2 @@! +data_bag_item[fluff]! Chef Client finished, 2 resources updated
  • 12. Learn more • From Zero to Chef in 8.5 Seconds • http://www.getchef.com/blog/2013/10/31/chef-client-z-fromzero-to-chef-in-8-5-seconds/ ! • Chef Docs Site • http://docs.opscode.com/release_notes.html#chef-client-localmode ! • Chef-Zero on GitHub • https://github.com/opscode/chef-zero