I have two cookbooks:
CookbookA and CookbookB
CookbookB has an attribute (e.g. "include_xyz") defined.
This should be set to "true" if CookbookA has run otherwise it should be set to "false".
How should "include_xyz" definition in CookbookB/attributes/default.rb look like?
Executing chef cookbook based on dependency
101 Views Asked by Haris Farooqui At
2
Since attribute files are all parsed (all of the attributes in all of the cookbooks which have been synchronized to the node), before any recipe code is executed, and before any
include_recipe "CookbookA"
statements could have been parsed this is impossible to solve accurately in attribute code.You can eliminate the attribute entirely and just make conditional code in recipes directly:
It's probably better to invert this logic, however, and write a wrapper cookbook around CookbookA which gets the behavior correct. You're trying to 'spy' on CookbookA when it will be simpler to assert the correct behavior. You could add an attribute which drove both the behavior in your cookbook and if CookbookA was included or not, and make that attribute an authoritative source of truth.