Top Banner
v1.2.3 Chef-Zero & Local Mode Michael Goetz Automation Consulting Engineer, Chef [email protected]
12

Chef-Zero & Local Mode

Jan 27, 2015

Download

Technology

Michael Goetz

A brief overview of Chef-Zero and using local mode to configure your infrastructure with Chef.
Welcome message from author
This document is posted to help you gain knowledge. Please leave a comment to let me know what you think about it! Share it to your friends and learn new things together.
Transcript
Page 1: Chef-Zero & Local Mode

v1.2.3

Chef-Zero & Local ModeMichael Goetz Automation Consulting Engineer, Chef [email protected]

Page 2: Chef-Zero & Local Mode

Back in my day…• Getting started with

Chef involved a lot of setup • Configure

workstation • Configure Chef

server • Bootstrap node

Page 3: Chef-Zero & Local Mode

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

Page 4: Chef-Zero & Local Mode

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

Page 5: Chef-Zero & Local Mode

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

restartshttp://www.nevinmartell.com/wp-content/uploads/2012/10/always_trust_a_skinny_chef.jpg

Page 6: Chef-Zero & Local Mode

But does it blend?• Search • Node data • Client data • Cookbooks • Data bags • Roles • Environments

Page 7: Chef-Zero & Local Mode

Using Chef-Zero• Install chef-zero gem

• • Start chef-zero server (defaults to 127.0.0.1:8889)

• • Setup knife.rb with server details

$ gem install chef-zero

$ chef-zero

chef_server_url 'http://127.0.0.1:8889' node_name 'tastesgreat' client_key ‘dummy_key.pem'

Page 8: Chef-Zero & Local Mode

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

Page 9: Chef-Zero & Local Mode

Going native with local mode• Harness the power of chef-zero

within chef-client • & • Loads files from current directory

• /cookbooks • /nodes • /roles • /environments

• Writes data changes back to local file system

• knife works too!http://www.prosperapartners.org/wp-content/uploads/2012/07/i-am-a-localist.png

chef-client -z knife -z

Page 10: Chef-Zero & Local Mode

{! "id": "fluff",! "clouds": "Are fluffy"!}

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”

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

cookbooks/zero/recipes/default.rb

data_bags/zero/fluff

Page 11: Chef-Zero & Local Mode

$ chef-client -z -o zero

Converge!

[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

Page 12: Chef-Zero & Local Mode

Learn more• From Zero to Chef in 8.5 Seconds

• http://www.getchef.com/blog/2013/10/31/chef-client-z-from-zero-to-chef-in-8-5-seconds/ !

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

mode !

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