Cookbook Directory

[edit on GitHub]

The cookbooks/ directory of your Chef Infra repository is used to store the cookbooks that Chef Infra Client uses in configuring the various systems in the organization.

Working with Cookbooks

Use the following knife subcommands to create, install, and/or download cookbooks.

Create

To create a cookbook (including all default components), run the following command:

chef generate cookbook COOKBOOK_NAME

where COOKBOOK_NAME is the name of the cookbook that will be created. Any unneeded directory components can be left unused or deleted, if preferred.

Install

To download a cookbook when git is used for version source control, run the following command:

knife supermarket install COOKBOOK_NAME

where COOKBOOK_NAME is the name of a cookbook on Chef Supermarket. This will start a process that:

  • downloads the cookbook from Chef Supermarket as a tar.gz archive
  • ensures that its using the git master branch, and then checks out the cookbook from a vendor branch (creating a new vendor branch, if required)
  • removes the old (existing) version
  • expands the tar.gz archive and adds the expanded files to the git index and commits
  • creates a tag for the version that was downloaded
  • checks out the master branch
  • merges the cookbook into the master (to ensure that any local changes or modifications are preserved)

Download

To download a cookbook when git is not used for version source control, run the following command:

knife supermarket download COOKBOOK_NAME

where COOKBOOK_NAME is the name of a cookbook on Chef Supermarket. This will download the tar.gz file associated with the cookbook and will create a file named COOKBOOK_NAME.tar.gz in the current directory (e.g., ~/chef-repo). Once downloaded, using a version source control system is recommended.

Cookbook Metadata

Every cookbook requires a small amount of metadata. A file named metadata.rb is located at the top of every cookbook directory structure. The contents of the metadata.rb file provides information that helps Chef Infra Client and Server correctly deploy cookbooks to each node.

Each cookbook can be configured to contain cookbook-specific copyright, email, and license data which is stored in the metadata.rb file.

You can configure default values for the copyright, email, and license of new cookbooks by adding the following to the config.rb file in the chef-repo:

cookbook_copyright "Example, Com."
cookbook_email     "[email protected]"
cookbook_license   "apachev2"

where the cookbook_copyright and cookbook_email are specific to the organization and cookbook_license is either apachev2 or none. These settings will be used in the default recipe and in corresponding values in the metadata.rb file, but can be modified in those locations as well (if they should be different from the default values contained in the config.rb file.)

For a full explanation of working with cookbook metadata, see metadata.rb.

© Chef Software, Inc.
Licensed under the Creative Commons Attribution 3.0 Unported License.
The Chef™ Mark and Chef Logo are either registered trademarks/service marks or trademarks/servicemarks of Chef, in the United States and other countries and are used with Chef Inc's permission.
We are not affiliated with, endorsed or sponsored by Chef Inc.
https://docs.chef.io/cookbook_repo/