- From: Noah Kantrowitz <
>
- To:
- Subject: [chef] Re: Understanding node attributes set from 'role' cookbooks
- Date: Fri, 14 Mar 2014 09:44:12 -0700
On Mar 14, 2014, at 5:44 AM, Lewis Thompson
<
>
wrote:
>
Hello,
>
>
I'm in the process of converting my roles into role cookbooks. A
>
minority of these roles set attributes and these are causing me
>
problems.
>
>
Assuming my cookbook a has the following in an attributes file:
>
>
default['a']['b'] = true
>
>
I can override this in a cookbook recipe as expected:
>
>
node.default['a']['b'] = false
>
>
However, as soon as attributes files start performing logic based on
>
attributes things break down as demonstrated in the following example
>
cookbook (roleattributes):
>
>
attributes file:
>
>
default['roleattributes']['test'] = true
>
if node['roleattributes']['test'] == true
>
default['roleattributes']['testistrue'] = true
>
else
>
default['roleattributes']['testistrue'] = false
>
end
>
>
default recipe:
>
>
node.normal['roleattributes']['test'] = false
>
require 'pp'
>
pp node.debug_value(:roleattributes, :test)
>
pp node.debug_value(:roleattributes, :testistrue)
>
>
The output from the pp command during a Chef run is (with all
>
not_present stripped for clarity):
>
>
# pp node.debug_value(:roleattributes, :test)
>
["default", true],
>
["normal", false],
>
# pp node.debug_value(:roleattributes, :testistrue)
>
["default", true],
>
>
As can be seen node['roleattributes']['test'] is correctly false while
>
node['roleattributes']['testistrue'] is true. By comparison when I
>
define roleattributes.test=false in my role normal attributes I get a
>
different result:
>
>
# pp node.debug_value(:roleattributes, :test)
>
["default", true],
>
["normal", false],
>
# pp node.debug_value(:roleattributes, :testistrue)
>
["default", false],
>
>
Is there any way around this somewhat unexpected (to me) behaviour?
>
At the moment it is holding up a full migration towards role cookbooks
>
(to allow versioning, etc.)
Move that logic into recipe or resource code so it can be lazily evaluated.
The problem is that attribute files are run once at the start a run so having
any logic based on values that might change later (either due to overrides or
anything else) doesn't change the outcome of that execution (since it already
happened).
--Noah
Attachment:
signature.asc
Description: Message signed with OpenPGP using GPGMail
Archive powered by MHonArc 2.6.16.