1

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

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. – Gaius Sep 16 '17 at 14:33
  • check now my answer – Berlin Sep 16 '17 at 14:38
  • 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. – Gaius Sep 18 '17 at 10:53

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.