<p>I think that according to chef documentation you should use <code>normal</code> with node data.</p>

<blockquote>
  <p>A normal attribute is a setting that persists in the node object. A
  normal attribute has a higher attribute precedence than a default
  attribute.</p>
</blockquote>

<p>you can read about it here:</p>

<p><a href="https://docs.chef.io/attributes.html" rel="nofollow noreferrer">https://docs.chef.io/attributes.html</a></p>

<p><a href="https://docs.chef.io/knife_node.html" rel="nofollow noreferrer">https://docs.chef.io/knife_node.html</a></p>

<p>some example:</p>

<pre><code>  "normal": {
    "ebs": {
      "devices": [
        {
          "mount_device": "/dev/xvdf",
          "encrypt": true,
          "volume_mapping": [
            {
              "device": "/dev/xvdf"
            }
          ]
        }
      ]
    },
</code></pre>

<p>In you recipe:</p>

<pre><code>if node.ebs.devices[0]['mount_device'] == '/dev/xvdf' and node.ebs.devices[0]['encrypt'] ...
</code></pre>

<p>Another example with <code>node['myattribute']</code></p>

<pre><code>   "normal": {
        "myattribute": "myvalue"
        },
</code></pre>

CC BY-SA 3.0
2017-09-16T14:33:48.847Z
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
CC BY-SA 3.0
2017-09-16T14:38:49.547Z
check now my answer
Berlin
CC BY-SA 3.0
2017-09-18T10:53:33.890Z
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
CC BY-SA 3.0
2017-09-16T14:28:12.983Z
2017-09-16T14:47:49.773Z
2017-09-16T14:47:49.773Z
Berlin
<p>Let us say I do <code>knife node edit mynode</code> and within the <code>normal</code> section I edit the JSON to add <code>"myattribute": "myvalue",</code>. I save this and verify that it has taken effect by issuing <code>knife search node -a myattribute mynode</code>, 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 <code>node['myattribute']</code> when running the recipe on <code>mynode</code> but that just returns nothing. The usual Ohai attributes such as <code>node['hostname']</code> obviously work as expected. </p>

<chef><configuration><configuration-management><infrastructure-as-code>
Accessing attributes from within recipes
Gaius
# Accessing attributes from within recipes

(Asked by: username_0 on 2017-09-16)

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.

**Tags:** chef, configuration, configuration-management, infrastructure-as-code


---

## 1 answers

### Answer by username_1 on 2017-09-16. Score: 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"
        },

> **Comments:**
> **username_0**: 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.  
> **username_1**: check now my answer  
> **username_0**: 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.  

---

