Reputation: 984
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?
Upvotes: 0
Views: 97
Reputation: 3974
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:
if node.recipe?('CookbookA')
# do stuff conditionally
end
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.
Upvotes: 0
Reputation: 984
Ahh got it!
default['include_xyz'] = "#{node.recipe?('CookbookA')}"
Upvotes: 0