Using attributes in Chef

+2 votes
Just getting started with using chef recently. I gather that attributes are stored in one large monolithic hash named node that's available for use in your recipes and templates.

There seem to be multiple ways of defining attributes

Can somebody explain the precedence?
Jul 5, 2018 in Chef by Hannah
• 16,210 points
412 views

3 answers to this question.

0 votes

Attributes are defined by:

  • The state of the node itself
  • Cookbooks (in attribute files and/or recipes)
  • Roles
  • Environments

Attributes are always applied by the chef-client in the following order:

  1. A default attribute located in a cookbook attribute file
  2. A default attribute located in a recipe
  3. A default attribute located in an environment
  4. A default attribute located in a role
  5. A force default attribute located in a cookbook attribute file
  6. A force default attribute located in a recipe
  7. A normal attribute located in a cookbook attribute file
  8. A normal attribute located in a recipe
  9. An override attribute located in a cookbook attribute file
  10. An override attribute located in a recipe
  11. An override attribute located in a role
  12. An override attribute located in an environment
  13. A force override attribute located in a cookbook attribute file
  14. A force override attribute located in a recipe
  15. An automatic attribute identified by Ohai at the start of the chef-client run

where the last attribute in the list is the one that is applied to the node.

answered Jul 5, 2018 by Kalgi
• 41,990 points
0 votes

Attributes are defined by:

  • The state of the node itself
  • Cookbooks (in attribute files and/or recipes)
  • Roles
  • Environments
answered Oct 23, 2018 by krishti
0 votes

There are 6 different types of attributes:

  • default: A default attribute is automatically reset at the start of every chef-client run and has the lowest attribute precedence. Use defaultattributes as often as possible in cookbooks.
  • force_default: Use the force_default attribute to ensure that an attribute defined in a cookbook (by an attribute file or by a recipe) takes precedence over a default attribute set by a role or an environment.
  • normal: A normal attribute is a setting that persists in the node object. A normal attribute has a higher attribute precedence than a defaultattribute.
  • override: An override attribute is automatically reset at the start of every chef-client run and has a higher attribute precedence than default, force_default, and normal attributes. An overrideattribute is most often specified in a recipe, but can be specified in an attribute file, for a role, and/or for an environment. A cookbook should be authored so that it uses override attributes only when required.
  • force_override: Use the force_override attribute to ensure that an attribute defined in a cookbook (by an attribute file or by a recipe) takes precedence over an override attribute set by a role or an environment.
  • automatic: An automatic attribute contains data that is identified by Ohai at the beginning of every chef-client run. An automatic attribute cannot be modified and always has the highest attribute precedence.
answered Oct 23, 2018 by Aditya

Related Questions In Chef

+5 votes
2 answers
0 votes
1 answer

How do I run chef client?

You've kinda answered your own question there. ...READ MORE

answered Jun 14, 2018 in Chef by ajs3033
• 7,280 points
34 views
0 votes
1 answer

Long running chef-client executions

You can try the following steps. Chef Server ...READ MORE

answered Jun 20, 2018 in Chef by shubham
• 6,890 points
37 views
0 votes
1 answer

How do I Force push a recipe to the end of run_list Iin Chef?

Here is a concept which you can ...READ MORE

answered Aug 7, 2018 in Chef by Damon Salvatore
• 5,510 points
68 views
+13 votes
2 answers

Git management technique when there are multiple customers and need multiple customization?

Consider this - In 'extended' Git-Flow, (Git-Multi-Flow, ...READ MORE

answered Mar 26, 2018 in DevOps & Agile by DragonLord999
• 8,380 points
204 views
0 votes
1 answer
+1 vote
2 answers

Unable To Create a Chef Node "ChefNode2"

Try giving the password to access your ...READ MORE

answered Oct 16, 2018 in Chef by Kalgi
• 41,990 points
315 views
0 votes
1 answer

How do I install chef on Ubuntu?

Hey @Yamini, follow these steps to install ...READ MORE

answered Feb 26 in Chef by Kalgi
• 41,990 points
70 views