1
votes

Suppose I am using 2 cookbooks cookbook A and B , each cookbook has a,b,c recipes in it. If I assigned both cookbooks to a node then what will be the execution sequence of the cookbooks and recipes?. which cookbook A or B will run first and what will be sequence of a,b,c. This problem applies to attributes file also in a,b,c,d four attributes file if I defined var as variable and used it in recipe then from which attribute file variable will be used. Please give some suggestions I am novice user to chef.

3
Read up on chef run-lists, which is an ordered list of recipes to run: docs.chef.io/nodes.html#about-run-listsDisplay Name is missing

3 Answers

0
votes

This is a bit more complex than it first appears. I have a cookbook that uses chefspec tests to demonstrate it, but sadly it got corrupted. I'll try to add it here when I get it fixed. Here's the answer for you.

Attributes

  1. Before any recipes execute, all attribute files execute.
  2. Attributes files are only executed if a recipe exists, in the same cookbook, with the same name.
    • attributes files that are included with include_attribute will run regardless of whether a corresponding recipe exists.
  3. No attribute file will be evaluated more than one time.
  4. By default, within a single cookbook, all attribute files will be evaluated in lexicographic order.
    • attribute files included with include_attribute will be evaluated at the point where they are first included, regardless of name
  5. I believe attribute files for each cookbook are evaluated when that cookbook is loaded (which I believe is in lexicographic order) - I have not yet confirmed this one.

Recipes

The recipes will execute in the order in which they appear in your runlist. - if a recipe is included by another using include_recipe it could, in theory, execute twice

0
votes

To complete Tejay answer:

The link of @DisplayNameismissing explain it but roughly: the runlist is expended, each dependency resolved, and the cookbooks are loaded in reverse order (deepest depend first)

Lets say I've 2 cookbooks

A depends on B and C X depends on Y

My runlist is X then A

The loading of cookbooks (and so attributes) will be Y -> X -> C -> B -> A

For the include_recipe, it can't run twice, if it's included more than once that will be ignored as its already in the runlist.

With chef client in version 11.16 and upper running with a log level of info will show you what is done at start of the run (for the order)

0
votes

Your cookbook will get executed in the order that you specify in the runlist. If you haven't specified which recipes to get executed, it will look for default recipe and execute that.

Let's you have two cookbooks A and B. You have added both cookbook into a role C. When you have a node associated with this role , cookbooks will get executed in the order that you specified in the role. Let's assume we have specified A first in the role. Then it would look for default recipe inside A.