Book Image

Configuration Management with Chef-Solo

By : Naveed ur Rahman
Book Image

Configuration Management with Chef-Solo

By: Naveed ur Rahman

Overview of this book

Table of Contents (13 chapters)

Attributes


Attributes are defined in a cookbook and then used to override the default settings on a machine. When chef-client executes, it loads all the recipes and checks for all the attributes in a node. Attributes defined in a cookbook take precedence over the default attributes. The chef-client applies new settings and values accordingly on a new node.

The order of the attributes' precedence is mentioned as follows:

  • A default attribute declared in cookbook attributes

  • A default attribute declared in a recipe

  • A default attribute declared in an environment

  • A default attribute declared in a role

Now, we will create a database name in our attributes/default.rb file and use it in the mysql_server resource:

# wpblog/recipes/default.rb
Default.wpblog.database = 'wpblog'
# Replace the name of database with attribute, now final resource will look like this:
   mysql_database node['wpblog']['database'] do
   connection (
:host => 'localhost',
:username => 'root',
:password =>	node['mysql']['server_root_password...