Chef environment variable question

Hi All,

If I have the following setup:

Cookbook CB ------->Recipe A --------------> ENV['foo']='bar' --------------> Include recipe C ------->Recipe B --------------> Bunch of resources ------->Recipe C --------------> Bunch of resources

Assume that the run_list contains A, B (but not C explicitly, although C is invoked via A using the include recipe statement within A)

Questions:

  1. Will the environment variable foo (defined in A) be available for resources within recipe C, i.e. when recipe C runs as part of A?
  2. Will the environment variable foo (defined in A) be available for resources defined in recipe B?

Thank you
Aravind

When you start asking questions about ordering or sequencing, always look at how the Ruby code itself will execute. include_recipe is a method that runs the code (recipe compile phase) at the point that Ruby causes the method to be executed. Similarly the ENV[]= is plain old Ruby code and happens when execution hits that line. Layered on top of this is Chef’s two-pass compile/converge structure. You can read a bit about that in https://coderanger.net/two-pass/.

tl;dr yes the variable would be set for all of them after that line runs.