One of the big advantages of using Chef is the availability of a wide arrange of existing recipes.  This page explains how to install cookbooks written and maintained by other people using vanilla Chef.

For Berkshelf; see here.

Installing an Opscode Community Cookbook

Installing a cookbook from the Opscode Community Cookbook site is simple:

  1. Identify the cookbook that you want to install.  Go to the Opscode Community site and either search or browse the cookbook catalogue.  Each cookbook include documentation describing what the cookbook's recipes (and other things) do, and how to use them.  There are links to the cookbook's development site, and various other useful information such as platform dependencies, versions, user ratings, and download counts.
  2. Change directory to your "chef-repo"
  3. Install the cookbook by running:

    knife cookbook site install <cookbook-name>

    This will do the following (copied from the "knife help"):

    1. A new "pristine copy" branch is created in git for tracking the upstream.
    2. All existing versions of a cookbook are removed from the branch.
    3. The cookbook is downloaded from https://cookbooks.opscode.com in the tar.gz format.
    4. The  downloaded cookbook is untarred and its contents are committed to git and a tag is created.
    5. The "pristine copy" branch is merged into the master branch.

    This process allows the upstream cookbook in the master  branch to be modified while letting git maintain changes as a separate patch. When an updated upstream version becomes available,  those changes can be merged while maintaining any local modifications.

  4. Push the newly installed cookbook to the relevant places.  For example:
    • Push the commits to your upstream Git repository.
    • Transfer to the "/var/chef-solo" directories on Chef solo managed machines.
    • Upload the cookbook to your Chef server.
  5. You can now add recipes from the newly installed cookbook to your node's run-lists, and so on.

Installing Cookbooks from Github

The "knife cookbook site" command only understands how to install cookbooks from the Community Cookbook site.  To install them from other sites, you need to install the "knife-github-cookbooks" plugin from here.  The procedure for installing a knife plugin is described here.

Once you have done that, you can use "knife" to install and maintain cookbooks from any Github repo; e.g.

knife cookbook github install cookbooks/yum
Filed under: