Search code examples
attributesvagrantchef-infrachef-solo

Chef cookbook not seeing overridden attributes in another cookbook


I have a run_list like this [ recipe["git_deploy"], recipe["my_role_cookbook"] ]
I set attributes that git_deploy needs in the default.rb recipe of my_role_cookbook. However, the git_deploy doesn't get these attributes. If I put the attribute needed by git_deploy in my_role_cookbook/attributes/default.rb, then it works. If I put lazy evaluation in git_deploy - it works as well.
I don't get why it doesn't work if I use node.override in the my_rolecook_book/recipes/default.rb

The bigger picture: I have three environments, and in the role file of my_role, I have env_run_lists like this:

"production" => ["recipe[git_deploy]","recipe[my_role]"],
"staging" =>["recipe[git_deploy]","recipe[my_role]"],
"develop" => ["recipe[my_role]"]

EDIT
After using debug_value in both cookbooks:

  • When using lazy evaluation in git_deploy(node.override used in my_role_cookbook/recipe/default.rb):

    • Chef::Log output from git_deploy
      [2015-07-31T11:44:12+00:00] FATAL: [["set_unless_enabled?", false], ["default", :not_present], ["env_default", :not_present], ["role_default", :not_present], ["force_default", :not_present], ["normal", :not_present], ["override", :not_present], ["role_override", :not_present], ["env_override", :not_present], ["force_override", :not_present], ["automatic", :not_present]]
    • LOG output from my_role_cookbook
      [2015-07-31T11:44:12+00:00] FATAL: [["set_unless_enabled?", false], ["default", :not_present], ["env_default", :not_present], ["role_default", :not_present], ["force_default", :not_present], ["normal", :not_present], ["override", "youtube-minion"], ["role_override", :not_present], ["env_override", :not_present], ["force_override", :not_present], ["automatic", :not_present]]
  • When not using lazy evaluation(only node.override in my_role_cookbook)

    • LOG from git_deploy. Right after the log with debug_value, the git_deploy fails with undefined method `[]' for nil:NilClass

    [2015-07-31T11:45:53+00:00] FATAL: [["set_unless_enabled?", false], ["default", :not_present], ["env_default", :not_present], ["role_default", :not_present], ["force_default", :not_present], ["normal", :not_present], ["override", :not_present], ["role_override", :not_present], ["env_override", :not_present], ["force_override", :not_present], ["automatic", :not_present]]

    • LOG from my_role_cookbook - this LOG is not shown, because the previous recipe fails.

Solution

  • All files inside attributes/* are merged and evaluated before any recipes run. Since you've put git_deploy first on your runlist, it's recipes run before yours. You must use attribute files in order to get your attributes injected before git deploy's recipes, and then your recipe, runs. Or put git_deploy as an include from your recipe.

    Here's a link with more on how attribute files work.