Skip to content

Instantly share code, notes, and snippets.

@lamont-granquist
Last active January 11, 2020 22:56
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save lamont-granquist/b559886607a72515f262 to your computer and use it in GitHub Desktop.
Save lamont-granquist/b559886607a72515f262 to your computer and use it in GitHub Desktop.

Why?

The chef-zero or "local-mode" of chef-client should be used to apply a cookbook to the server that you run it on without involving a full blown Chef Server of any kind. It does this by firing up a mini chef server that requires zero configuration in the background and uploding your cookbooks to it and doing a real chef-client converge against it, completely transparently. This allows you to use all the features of Chef without the need to think about running a server.

Other Options

There is also the chef-solo utility that is similar, but is limited in that it cannot talk to a chef server at all, and therefore features like search are architecturally broken. Ideally, it should not be used for new development work.

The chef-apply utility that can be used to converge resources in a single file against a host without a server and without any cookbook structure at all. Since there is no available structure other than the recipe file features like search, data bags, templates and other resources are architecturally broken. It is most useful for quickly testing some of the resources which do not require talking to a chef server.

Chef Zero in 30 Seconds

create a directory for a sandbox:

mkdir ~/zero
cd ~/zero

create a cookbooks directory under that, with single 'test' cookbook and a single 'default.rb' recipe:

mkdir -p cookbooks/test/recipes
vim cookbooks/test/recipes/default.rb

put some resources in your recipe:

file "/tmp/arglebargle" do
  content "arglebargle"
end

converge:

chef-client -z -r 'recipe[test::default]'

Roles, Data Bags, Environments, etc

Put them alongside the cookbooks directory just like in a normal chef-repo:

mkdir {roles,data_bags,environments}

JSON node options

For setting arbitrary node data (or setting the run_list via the JSON and not the -r option), use the -j option:

vim dna.json

with contents like:

{
  "run_list": [ "recipe[test::default]" ]
}

and run:

chef-client -z -j dna.json
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment