Permalink
Switch branches/tags
818-check 953-ce 997-ce 1010-ce 1012-ce 1015-ce 1050-ce 1050.ce 1062-ce 1092-ce 1104-ce 1110-ce 1113-ce 1114-ce 1122-ce 1149-ce 1157-ce 1178-ce 1194-reopen 1238-ce 1250-ce 1251-ce 1252-ce 1257-ce 1308-ce SUSTAIN-788/reaper-config TheLunaticScripter-patch-1 ap/compliance-migration ap/update-automate-api-docs ascii aws-example-backups backend-failure-recovery btm/audit_mode cdn/automate-upgrade-nopostun chef-12-eol chef-13-resource-cloning chef-14-more-resources chef-14-resources chef-14-updated-resources chef-14-windows-resources chef-server-file chef-server-full-path chef-zero chefdk-install-restructure compliance-ga cookbook-s3-external-url credentials-mgmt ctl-automate-fix-typo data-collector debian-eol-policy deprecation-chocolatey-uninstall deprecation-deploy dw/automate_rel_note_updates dw/automate_1.7_bug_fix dw/less_verbose dw/update_jquery edit-resource-syntax enable-request-logging-version-tags eol-links es-and-ls-tunables fips-chef-client fix-buildkite-failures fix-chef-overview fix-data-retention-edit-link fix-plural-reporting-install fix-typo habitat-prism-removal install-dk-dpkg-rpm jcd/rewrite-support-policy jdm/include_policy jjasghar/centos7_install jjasghar/erchef jjasghar/sudo jjh/data_bag_item_example_use_abstraction jm/chefdk_3_4_release_notes kagarmoe-patch-1 kagarmoe-patch-2 kg/API-reporting kg/AWS-Auto kg/Visibility-more kg/audit-tables kg/auto-notes kg/auto17x-sidebar kg/automate_compliance kg/automate18 kg/azureportal kg/callitchef kg/compliance-api-update kg/compliance-latest kg/compliance-update kg/data-summary kg/dc-stubs kg/es-data-coll kg/fix-redirects kg/github kg/gitignore kg/kibana kg/merge-conficts kg/node-visibility kg/omnibus-list kg/privacy_policy kg/redirect3 kg/redirects kg/redirects2 kg/release_automate_18x kg/release_notes_17 kg/rename-client-page kg/resource-nav kg/sidebar-edit kg/two-guides kg/update-compliance kg/visibility kg/workstaion-shell kg/17x-automate-ctl kg/17xAdmin-Setup kgarmoe/number9 knife-environment-create lcg/deprecate-run-command lcg/namespace_collisions link-cleanup manage-symlink-source master mj/deprec mj/warning1 mjdkfixin multi-servers-automate mwrock-2016-1 mwrock-2016 nb/before-notification-example nb/bookshelf-sql nb/chef-airgap nb/chefdk-1-5-release-notes nb/client-13-2-release-notes nb/knife-links nb/knife-node-status nb/next-steps-automate nb/release-notes-server-12-16-9 nb/release-notes-title-updates nb/removing-for nb/rhel-system-z-support nb/server-backup nb/sphinx-build-updates nginx-welcome-page ohai-7 openstack-redirect pdf_builder platforms-table-width-adjustment praj/SUSTAIN-600 praj/delete_runner private-supermarket-install pwm/adroll rel-notes-automate-1-8-38 rel-notes-automate-dec-17 rel-notes-chef-14-update rel-notes-client-12-22-3 rel-notes-client-13-7-16 rel-notes-client-13-8 rel-notes-dk-1-6-11 rel-notes-dk-2-4-17 rel-notes-server-12-17-15 rel-notes-server-12-17-33 release-notes-chef-14 release-notes-chef-dk-2-2-1 release-notes-client-12-21-31 release-notes-dk-2-3-3 release-notes-dk-2-3-4 release-notes-server-12-16-14 relnotes-client-13-6-4 relnotes-client-various relnotes-dk-2-5 remove-compliance-release-notes remove-knife-sort remove-prism remove-ref-links2 remove-selinux-note remove-sphinx-links-pt-2 remove-vsphere resource_cleanup_v6 resource_cleanup_v9 resource_hostname resource_macos_userdefaults resource_ohai_hint resource_openssl_dhparam resource_openssl_rsa_private_key resource_openssl_rsa_public_key resource_rhsm_errata revert-948-kg/redirects revert-950-kg/redirects2 revert-1053-documentation-ip revert-1075-kg/node-visibility revert-1194-dh/update_doc_windows_service revert-1302-revert-windows-service-chef-14 revert-chef-14-stuff revert-windows-service-chef-14 robb/add-more-details-to-supermarket-reqs schisamo/automate-updates server-security sh/clarify-FIPS-statement sh/clarify-attr-file-load sh/deprecate-hide-healthy sh/document-veil-data-collector sh/example-auto-attribs sh/reindex-w-option-note sh/remove-obsolete-type sh/resize-volumes-online sh/update-fips-mode-support sh/webui-IE-issue shain/fix_bk_code shain/terraform sidebar-removals sp/windows-2019 ssd/SUSTAIN-751-2 ssd/SUSTAIN-751 ssd/chef-backend-1.4-setting ssd/chef-backend-upgrade-directions ssd/es-stale-lock-option ssd/sustain-751 stuart/windows-8-eol supermarket-contribute supermarket-options supermarket-s3 syntax-fix-relnotes-1-8-3 systemd-unit-example template-cookstyle template-copy test-provider-rebase thomascate-add-node-cleanup tm/policyfiles tm/solo_updates trevorghess-patch-1 troubleshooting-syntax true-false-class use-runners-not-build-nodes web windows-dism-fix windows-task-copy-edits workstation-syntax-fix
Nothing to show
Find file Copy path
Fetching contributors…
Cannot retrieve contributors at this time
99 lines (74 sloc) 6.08 KB

About Cookbooks

[edit on GitHub]

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
  • Templates
  • Extensions to Chef, such as custom resources and libraries

The chef-client uses Ruby as its reference language for creating cookbooks and defining recipes, with an extended DSL for specific resources. The chef-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.

Components

Some important components of cookbooks include:

Feature Description
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-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, the chef-client will apply those new settings and values during the chef-client run on the node.
Recipes

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 the chef-client
  • Is always executed in the same order as listed in a run-list

The chef-client will run a recipe only when asked. When the chef-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, the chef-client won't change anything.

In addition to attributes and recipes, the following items are also part of cookbooks:

Components Description
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 A library allows the use of arbitrary Ruby code in a cookbook, either as a way to extend the chef-client language or to implement a new class.
Custom 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.
Metadata A metadata file is used to ensure that each cookbook is correctly deployed to each node.
Resources A resource instructs the chef-client to complete various tasks like installing packages, running Ruby code, or accessing directories and file systems. The chef-client includes built-in resources that cover many common scenarios. For the full list of resources that are built-in to the chef-client, see /resources.html.
Templates A template is a file written in markup language that uses Ruby statements to solve complex configuration scenarios.
Cookbook Versioning

A cookbook version represents a set of functionality that is different from the cookbook on which it is based. A version may exist for many reasons, such as ensuring the correct use of a third-party component, updating a bug fix, or adding an improvement. A cookbook version is defined using syntax and operators, may be associated with environments, cookbook metadata, and/or run-lists, and may be frozen (to prevent unwanted updates from being made).

A cookbook version is maintained just like a cookbook, with regard to source control, uploading it to the Chef server, and how the chef-client applies that cookbook when configuring nodes.

Community Cookbooks

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

Components Description
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.