4

I'm trying to get a grasp on chef and for the life of me I cannot find how cook books are run

If I have the file structure

chef-repo
├── cookbooks
│   └── test
│       ├── attributes
│       │   ├── default.rb
│       │   └── test.rb
│       ├── files...
│       ├── metadata.rb
│       ├── recipes
│       │   ├── default.rb
│       │   └── test.rb
│       └── templates...
├── roles
│   └── starter.rb
└── Vagrantfile

How are the attributes loaded and in what order? eg it loads all the attributes (default.rb and test.rb) with default.rb always loaded first

How are the recipes run? eg only default.rb is run and everything , or all are run in alphabetical order.

I've found http://docs.opscode.com/essentials_nodes_chef_run.html but it doesn't explain cookbook execution only node level execution. Any resources or links to chef docs would be appreciated

Cheers

codeforester
  • 39,467
  • 16
  • 112
  • 140
Chris Barrett
  • 516
  • 3
  • 12
  • 1
    A chef node is bootstrapped with a role; the role (for each environment eventually) has a runlist made of other roles or recipes, which is determined by chef using what you directly configure in the role itself plus the transitive dependencies. – guido Apr 27 '14 at 01:17
  • Chef 11 fixed a bug where attribute files were loaded randomly. See: https://tickets.opscode.com/browse/CHEF-2903 – Mark O'Connor Apr 27 '14 at 13:46

1 Answers1

4

Recipes are run in the order they occur in the runlist. Only recipes that occur in the run list will be executed (plus any recipes that are included in place using include_recipe. Note that each recipe will only run once, even if it occurs multiple times in the runlist.

Attribute files from cookbooks are loaded in this order:

  1. Attributes of dependencies (i.e. cookbooks declared with depends in metadata.rb
  2. attributes/default.rb
  3. all other attributes files in alphabetical order.

Note that all attribute files in a cookbook are loaded, regardless of their name. Only attributes of cookbooks which either explicitly occur in the resolved runlist (i.e. recipes loaded by roles or explicit inclusion into the runlist) or which are dependencies of their cookbooks will be loaded.

Holger Just
  • 52,918
  • 14
  • 115
  • 123