Say I have the following chef role:
name "test"
description "role for test"
run_list %w(recipe[cookbook_name])
default_attributes(
:cookbook_name => {
:a => 1
}
)
And the corresponding environment:
name "test environment"
description "environment for test"
default_attributes(
:cookbook_name => {
:b => 2
}
)
And then in my cookbook’s attributes I have something like:
parent = default[:cookbook_name]
parent[:c] = 3
The attribute documentation would have me believe that these would be available in the recipe context from node[:cookbook_name][:a] or node[:cookbook_name][:b]. However, when I try to access those in my actual cookbook, I get nil. What’s going on? Am I misunderstanding the role of these attributes? I think that it’s worth noting that even if I set defaults for these attributes in the attributes file, I get the same result, leading me to believe I’m accessing the attributes incorrectly.
What am I doing wrong?
This is indeed how things should work. Inside the “cookbook_name” recipe you should be able to access the
:cookbook_namehash with two elements:aand:b.Have you set the run list and environment on the node to include the role and environment you have listed? Running
knife node showshould show this.