Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p><a href="http://docs.opscode.com/chef_overview_attributes.html" rel="nofollow noreferrer">The Chef Documentation</a> has a <a href="http://docs.opscode.com/_images/overview_chef_attributes_table.png" rel="nofollow noreferrer">table showing the node attribute precedence</a>. If you edit a node object on the Chef server, or provide node attributes with a JSON file (<code>-j</code> option to chef-solo or chef-client), these are all the "node" level. This is the same level as setting attributes from a recipe. To whit, you can easily set any level of node attribute in a recipe w/ the attribute methods (node.normal, etc) except automatic. On the node object itself (in the Chef Server), you can set default, normal, and override, but not force_default or force_override, nor automatic.</p> <p>The general guideline we tell people is to always use default attributes:</p> <ol> <li><code>default['thing'] = 'thang'</code> - in a cookbook's attributes file.</li> <li><code>node.default['thing'] = 'thang'</code> - in a recipe.</li> <li><code>"default": { "thing": "thang" }</code> - in the node object's JSON</li> <li><code>default_attributes("thing" =&gt; "thang")</code> - in a role (<a href="http://docs.opscode.com/essentials_roles.html#ruby-dsl" rel="nofollow noreferrer">ruby DSL syntax shown</a>).</li> <li>Generally avoid <code>environment</code> set attributes...</li> </ol> <p>And when the need arises for you to set attributes elsewhere at other priorities, you will just know. :)</p> <p>It may seem arbitrarily over-engineered; originally there were only the node object/recipe and attributes files, and they were just Ruby hashes. Then we added roles, and environments. At some point in there too came the need to set "default" values that could be overridden easily, arbitrarily for various organizational reasons, and now we have the matrix you see today. We're pretty happy with things now, and think it provides the most flexibility for the extremely wide variety of Chef use cases.</p> <p><strong>Note</strong></p> <p>This question is not a duplicate of <a href="https://stackoverflow.com/questions/20717804/chef-versioning-is-there-an-order-of-precedence">chef versioning - is there an order of precedence</a> - that question pertains to cookbook versions, and this question pertains to node attribute precedence.</p> <p>Also note that because recipes are Ruby, and executed by the client you can write libraries to manipulate attributes in interesting ways. An example is <a href="http://community.opscode.com/cookbooks/whitelist-node-attrs" rel="nofollow noreferrer">Chef's whitelist-node-attrs cookbook</a>.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload