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