Let us say I do knife node edit mynode
and within the normal
section I edit the JSON to add "myattribute": "myvalue",
. I save this and verify that it has taken effect by issuing knife search node -a myattribute mynode
, and I see it there. How would I then use this value from within a recipe? I would have expected to just be able to say node['myattribute']
when running the recipe on mynode
but that just returns nothing. The usual Ohai attributes such as node['hostname']
obviously work as expected.
1 Answer
I think that according to chef documentation you should use normal
with node data.
A normal attribute is a setting that persists in the node object. A normal attribute has a higher attribute precedence than a default attribute.
you can read about it here:
https://docs.chef.io/attributes.html
https://docs.chef.io/knife_node.html
some example:
"normal": {
"ebs": {
"devices": [
{
"mount_device": "/dev/xvdf",
"encrypt": true,
"volume_mapping": [
{
"device": "/dev/xvdf"
}
]
}
]
},
In you recipe:
if node.ebs.devices[0]['mount_device'] == '/dev/xvdf' and node.ebs.devices[0]['encrypt'] ...
Another example with node['myattribute']
"normal": {
"myattribute": "myvalue"
},
-
I've read all the documentation but my question is not answered there - what I am struggling with is accessing an attribute set within the
normal
section from within a recipe.– GaiusSep 16, 2017 at 14:33 -
-
This does not work (and is one of the things I tried before posting the question). I agree it "ought" to as per the docs, but it returns nothing.– GaiusSep 18, 2017 at 10:53