Attributes represent information about your node. In addition to the information that can be automatically generated by ohai, you can set attributes in Chef recipes or in separate attribute files.
Because attributes can be defined in multiple places, all attribute values are composed together during a Chef run according to the priority levels
Attributes defined byย ohaiย have the highest priority, followed by attributes defined in a recipe, then attributes defined in an attribute file. In other words, recipe attributes have a higher priority than those defined in attribute file in cookbooks, and will override them by default. Attributes defined byย ohaiย trump everything else.
Declaring Attributes in Chef Recipe
Attributes can be set directly in recipes. Image shows the format of an attribute when it is set in a recipe. You must precede the attribute name with node. when you set an attribute directly in a recipe.

node.default['devopsschool']['message'] = 'Hello People'
log "Welcome to Chef, #{node['devopsschool']['message']}!" do
level :info
end
log "Welcome to DevOps" do
level :info
endCode language: PHP (php)
node.default['web']['file'] = '/opt/index.html'
file "#{node['web']['file']}" do
content "Welcome to Chef Class"
endCode language: PHP (php)

Declaring Attributes in Chef Cookbooks
Attribute files are located in the attributes folder of a cookbook. Similar to recipes, the default attribute file is called:


In cookbook, I visualize three levels of attributes:
– Default values to converge successfully — attributes/default.rb
– Local testing override values — JSON or .kitchen.yml (have you tried chef_zero using ChefDK and Kitchen?)
– Environment/role override values
SUMMARY of Attributes in Recipe and Cookbook
In an attributes file you don't have to type 'node' so that this in attributes/default.rb:
default['foo']['bar']['baz'] = 'qux'
In an recipes/whatever.rb file
node.default['foo']['bar']['baz'] = 'qux'Code language: PHP (php)I’m Rajesh Kumar, a DevOps, SRE, DevSecOps, Cloud, and Platform Engineering expert passionate about sharing practical knowledge, real-world experiences, and industry best practices. I have worked at Cotocus and regularly write about technology, travel, investing, health, product reviews, and digital marketing through my various platforms.
I publish technical articles at DevOps School, travel stories at Holiday Landmark, stock market insights at Stocks Mantra, health and fitness guidance at My Medic Plus, product reviews at TrueReviewNow, and SEO and digital marketing strategies at Wizbrand.
Find Trusted Cardiac Hospitals
Compare heart hospitals by city and services โ all in one place.
Explore Hospitals