A cookbook is the fundamental unit of configuration and policy distribution. A cookbook defines a scenario and contains everything that is required to support that scenario:
- Recipes that specify the resources to use and the order in which they are to be applied
- Attribute values
- File distributions
- Extensions to Chef, such as custom resources and libraries
Chef Infra Client uses Ruby as its reference language for creating cookbooks and defining recipes, with an extended DSL for specific resources. Chef Infra Client provides a reasonable set of resources, enough to support many of the most common infrastructure automation scenarios; however, this DSL can also be extended when additional resources and capabilities are required.
Chef Infra Client will run a recipe only when asked. 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 won’t change anything.
A cookbook is comprised of recipes and other optional components as files or directories.
A recipe is the most fundamental configuration element within the organization. A recipe:
|Attributes||attributes/||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 |
|Files||files/||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.|
|Libraries||libraries/||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 Resources||resources/||A custom resource is an abstract approach for defining a set of actions and (for each action) a set of properties and validation parameters.|
|Templates||templates/||A template is a file written in markup language that uses Ruby statements to solve complex configuration scenarios.|
|Ohai Plugins||ohai/||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.|
|Metadata||metadata.rb||This file contains information about the cookbook such as the cookbook name, description, and version.|
Chef maintains a large collection of cookbooks. In addition, there are thousands of cookbooks created and maintained by the community:
|Cookbooks Maintained by Chef||Chef maintains a collection of cookbooks that are widely used by the community.|
|Cookbooks Maintained by the Community||The community has authored thousands of cookbooks, ranging from niche cookbooks that are used by only a few organizations to cookbooks that are some of the most popular and are used by nearly everyone.|