Find the Best Cosmetic Hospitals

Explore trusted cosmetic hospitals and make a confident choice for your transformation.

โ€œInvest in yourself โ€” your confidence is always worth it.โ€

Explore Cosmetic Hospitals

Start your journey today โ€” compare options in one place.

Chef Tutorials: Working with Chef Attributes

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)

Find Trusted Cardiac Hospitals

Compare heart hospitals by city and services โ€” all in one place.

Explore Hospitals

Similar Posts

Subscribe
Notify of
guest
0 Comments
Newest
Oldest Most Voted
Inline Feedbacks
View all comments