Skip to main content

About Cookbooks

A cookbook is the fundamental unit of configuration and policy distribution in Chef Infra.

A cookbook defines a scenario and contains everything that is required to support that scenario:

  • Recipes that specify which Chef Infra built-in resources to use, as well as the order in which they are to be applied
  • Attribute values, which allow environment-based configurations such as dev or production.
  • Custom Resources for extending Chef Infra beyond the built-in resources.
  • Files and Templates for distributing information to systems.
  • Custom Ohai Plugins for extending system configuration collection beyond the Ohai defaults.
  • The metadata.rb file, which describes the cookbook itself and any dependencies it may have.
The Chef Infra Language is based on Ruby, allowing you to utilize the power of Ruby when the built-in language doesn’t meet your needs out of the box. If you’d like to learn more about extending your Chef Infra code by using Ruby see our Ruby Guide for further information on Ruby functionality. The Chef Infra Language is a comprehensive systems configuration language with resources and helpers for configuring operating systems. The language is primarily used in Chef Infra recipes and custom resources to tell the Chef Infra Client what action(s) to take to configure a system. The Chef Infra Language provides resources for system-level components such as packages, users, or firewalls, and it also includes helpers to allow you to make configuration decisions based on operating systems, clouds, virtualization hypervisors, and more.

Chef Infra Client runs a recipe only when instructed. When Chef Infra Client runs the same recipe more than once, the results will be the same system state each time. When a recipe is run against a system, but nothing has changed on either the system or in the recipe, Chef Infra Client will not change anything.


A cookbook is comprised of recipes and other optional components as files or directories.

ComponentFile/Directory NameDescription

A recipe is the most fundamental configuration element within the organization. A recipe:

  • Is authored using Ruby, which is a programming language designed to read and behave in a predictable manner
  • Is mostly a collection of resources, defined using patterns (resource names, attribute-value pairs, and actions); helper code is added around this using Ruby, when needed
  • Must define everything that is required to configure part of a system
  • Must be stored in a cookbook
  • May be included in another recipe
  • May use the results of a search query and read the contents of a data bag (including an encrypted data bag)
  • May have a dependency on one (or more) recipes
  • Must be added to a run-list before it can be used by Chef Infra Client
  • Is always executed in the same order as listed in a run-list
Attributesattributes/An attribute can be defined in a cookbook (or a recipe) and then used to override the default settings on a node. When a cookbook is loaded during a Chef Infra Client run, these attributes are compared to the attributes that are already present on the node. Attributes that are defined in attribute files are first loaded according to cookbook order. For each cookbook, attributes in the default.rb file are loaded first, and then additional attribute files (if present) are loaded in lexical sort order. When the cookbook attributes take precedence over the default attributes, Chef Infra Client applies those new settings and values during a Chef Infra Client run on the node.
Filesfiles/A file distribution is a specific type of resource that tells a cookbook how to distribute files, including by node, by platform, or by file version.
Librarieslibraries/A library allows the use of arbitrary Ruby code in a cookbook, either as a way to extend the Chef Infra Client language or to implement a new class.
Custom Resourcesresources/A custom resource is an abstract approach for defining a set of actions and (for each action) a set of properties and validation parameters.
Templatestemplates/A template is a file written in markup language that uses Ruby statements to solve complex configuration scenarios.
Ohai Pluginsohai/Custom Ohai plugins can be written to load additional information about your nodes to be used in recipes. This requires Chef Infra Server 12.18.14 or later.
Metadatametadata.rbThis file contains information about the cookbook such as the cookbook name, description, and version.

Community Cookbooks

Chef maintains a large collection of cookbooks. In addition, there are thousands of cookbooks created and maintained by the community:

Cookbooks Maintained by ChefChef maintains a collection of cookbooks that are widely used by the community.
Cookbooks Maintained by Sous ChefsSous Chefs is a community organization that collaborates to maintain many of the most used Chef cookbooks.
Cookbooks Maintained by the CommunityThe community has authored thousands of cookbooks, ranging from niche cookbooks that are used by only a few organizations to popular cookbooks used by almost everyone.

Generate a Cookbook

Use the chef generate cookbook subcommand to generate a cookbook.

A cookbook generated withchef generate cookbook custom_web creates a cookbook named custom_web with the directory structure:

. cookbooks
└── custom_web
    ├── LICENSE
    ├── Policyfile.rb
    ├── chefignore
    ├── compliance
    │   ├──
    │   ├── inputs
    │   ├── profiles
    │   └── waivers
    ├── kitchen.yml
    ├── metadata.rb
    ├── recipes
    │   └── default.rb
    └── test
        └── integration
            └── default
                └── default_test.rb
Edit this page on GitHub

Thank you for your feedback!


Search Results