- From: Gregory Patmore <
>
- To: "
" <
>
- Subject: [chef] Re: Understanding node attributes set from 'role' cookbooks
- Date: Fri, 14 Mar 2014 08:51:50 -0400
I think you want node.override here
http://docs.opscode.com/essentials_cookbook_attribute_files.html
post back if this doesn't work for you. generally a good idea to avoid
overrides, but when dealing with cookbooks from various sources, sadly this
happens more then one would want.
Greg
Sent from my iPhone
>
On Mar 14, 2014, at 8: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.)
>
>
Many thanks
>
>
Lewis
Archive powered by MHonArc 2.6.16.