Skip to content
Tutorials Center
My learning

Topics

Lesson 2 of 37 ยท Getting Started

Chef Vocabulary and Workflow

Learn the core Chef words: resource, recipe, cookbook, node, run list, attribute and Chef Infra Client, and see how they fit in a typical workflow from code to node.

Chef has its own vocabulary, and most beginner confusion comes from mixing up the words. This lesson defines each term once, shows how the pieces nest inside each other and walks through the day-to-day workflow. Come back to it whenever a later lesson uses a term you have forgotten.

The building blocks

The Chef building blocks

Resource One thing to manage
Recipe A list of resources
Cookbook Recipes plus files
Node A managed machine

Small to large: resource, recipe, cookbook.

1 / 2
  • A resource describes one piece of the system and its desired state: a package, a file, a service, a user.
  • A recipe is a Ruby file that lists resources in the order they should be applied.
  • A cookbook is a folder (and the unit of sharing) that groups recipes with the templates, files, attributes and tests they need.
  • A node is any machine managed by Chef: a server, a virtual machine, a container host or a cloud instance.
  • An attribute is a piece of data about a node (a port number, a package version, the operating system name).
  • A run list is the ordered list of recipes (or roles) that a node should apply.
  • Chef Infra Client is the program on the node that reads the run list and converges the node.
  • Chef Infra Server is the central place that stores cookbooks and node data (more in the architecture lesson).

How they nest

A cookbook contains recipes, and a recipe contains resources:

TEXT
cookbook: webserver
  recipes/
    default.rb        <- recipe
      package 'nginx' <- resource
      service 'nginx' <- resource
    ssl.rb            <- another recipe
  attributes/default.rb
  templates/nginx.conf.erb
  metadata.rb

When you put webserver in a node's run list, you apply its default recipe. The notation recipe[webserver::ssl] picks a different recipe from the same cookbook. You will see this notation constantly.

The typical workflow

  1. Write a recipe on your workstation.
  2. Test it locally (with Test Kitchen or local mode).
  3. Upload the cookbook to a Chef Infra Server (or keep it in a Policyfile archive).
  4. Assign it to nodes through a run list.
  5. Converge: Chef Infra Client runs on each node, usually every 30 minutes, and fixes any drift.
flowchart LR
  A["Write recipe"] --> B["Test locally"]
  B --> C["Upload cookbook"]
  C --> D["Set run list"]
  D --> E["chef-client converges node"]
  E --> F["Node reports results"]

The loop never really ends: the client keeps checking and correcting the node.

The vocabulary as Ruby data

A stand-in can make the nesting concrete. Here a cookbook is a hash of recipes, each recipe is a list of resource descriptions, and a run list picks recipes by name. This is not real Chef, just a model you can explore.

Ruby Stand-in: cookbooks, recipes, resources and a run list

Press Run (or Ctrl + Enter) to see the result here.

Program input ยท what you'd type while the program runs

Type the answers before you press Run, one per line. Each time the program reads a line (with gets), it gets the next line from this box.

The output order follows the run list, and inside each recipe it follows the order of the resources. Order matters in Chef: resources run top to bottom, so install a package before you start its service.

Attributes tune recipes

Recipes should not hard-code values that change between environments. Instead they read attributes. The stand-in below builds one resource list from a port attribute, so the same "recipe" gives different results for different nodes.

Ruby Stand-in: one recipe, different attributes

Press Run (or Ctrl + Enter) to see the result here.

Program input ยท what you'd type while the program runs

Type the answers before you press Run, one per line. Each time the program reads a line (with gets), it gets the next line from this box.

You will meet the real attribute system, with its 15 precedence levels, in Attributes and Precedence.

Name things for what they do, not for the server. A cookbook called postgresql is reusable, while server42-stuff is not. Small, focused cookbooks are easier to test and share.

Check your understanding

Quick check ยท 4 questions

of 4 answered You scored / 4 ยท perfect!

  1. 1. Which list correctly goes from smallest to largest unit?

    Resources are the smallest unit, recipes group resources, and cookbooks group recipes with their supporting files.
  2. 2. What does recipe[webserver::ssl] in a run list mean?

    The format is cookbook::recipe. Without the part after the colons, the recipe is default.
  3. 3. Where does the program that applies a run list to a machine live?

    Chef Infra Client is installed on each node and converges it.
  4. 4. Why does the order of resources in a recipe matter?

    Resources are applied in the order they appear, so dependencies must be written first.

Summary

  • Resource, recipe and cookbook nest from small to large; a node runs a run list of recipes.
  • Attributes are data that make recipes reusable.
  • Chef Infra Client applies the run list on the node; the server stores cookbooks and node data.
  • Resources run in written order.

Next: Your First Recipe