Chef: use knife to bootstrap nodes with chef-zero and Berkshelf

There are many reasons why you might not want to have Chef Server in your deployment path.  Or, as this example shows, you don’t want to host your own Chef Server.  We instead use Hosted Chef, but purely as a cookbook repository.  We will not have any nodes communicate directly with Chef Server, so we will not have to worry about the five-node limit for free accounts.

As with any knife bootstrap  method, this is not suitable for auto-scaling.  I will post an article on auto-scaling with Chef sometime in the future.

Let’s get started.

First, you will need to create a Hosted Chef account.  Go ahead and do that while I wait.

Assuming you already have ChefDK installed, we install knife-zero:

Save the following as ~/.chef/knife.rb  and update as needed:

All the values in brackets need to be updated, and are found in your Hosted Chef account.

This knife.rb uses Berkshelf to create a chef-repo  style structure from your cookbook directory.  If you have any of roles ,  environments , or  data_bags  directories in your cookbook directory, they will be symlinked correctly so that it follows the correct directory structure.  Otherwise, using any of these features would not work correctly.

Go into the Chef cookbook directory you’d like to apply to a node.  You can apply the cookbook as follows:

You will notice that Berkshelf will download all of your cookbooks from Chef or Supermarket and install them in /tmp/berkshelf/cookbooks .  The entire /tmp/berkshelf  directory is copied to the node, and chef-client is run in local mode using the arguments you passed.

So long as your run_list had no issues, you should see your run complete successfully.  Congratulations!

Leave a Reply

Your email address will not be published. Required fields are marked *