Chef : Configuration Management Tool

Chef : Configuration Management Tool

Pull Based Configuration Management Tool

Pull configuration nodes checks out with the servers periodically and fetches the configuration about it. In simple language, here PCs automatically check upon themselves whether they need an update or not? So the PCs pull the updates from the servers.

The most famous tool used for pull based configuration is Chef but some people may also use Puppet.

What is Chef?

Chef is a famous Pull-Based Configuration tool used to automate a lot of work. Some factoids about it are as follows:

  • Chef tool was made using Ruby and Erlang Language.

  • It's used to automate admin tasks.

  • It's an open source software.

Chef Architecture

Basically it consists of a workstation, a chef-server and a number of nodes(PCs).

Workstation
It consists of cookbooks, recipes and some other already installed files. On workstation we write our code in Ruby language on Linux. Recipes are files in which our code is written and is saved as recipe.rb where '.rb' is for ruby. These recipes are stored in a cookbook and multiple cookbook are stored in a folder called cookbooks.
Chef-server
In order to push updates on to the chef-server from workstation we use a command called as Knife. Our cookbook is also stored in chef servers.
Nodes
Different nodes consists of chef-client and ohai. Here, Ohai term is used to call a space or a database which has all the information, specifications & minute configuration about the node. Chef-Client is a tool which first checks whether the thing is already present in the node or not by asking Ohai and if not, then chef-client helps to bring the code or the updates from the servers to nodes.

Installation Process

To install Chef on your Linux machines use these following commands:

sudo su
wget https://packages.chef.io/files/stable/chef-workstation/0.4.2/el/7/chef-workstation-0.4.2-1.el6.x86_64.rpm
 yum install chef-workstation-0.4.2-1.e16.x86 64.rpm -y

Keep in mind version may differ.

Chef Commands

  1. Create a directory which store all the cookbook

     mkdir cookbooks
    
  2. Create a file/cookbook inside the cookbooks.

     chef generate cookbook test-cookbook #test-cookbook is name of a cookbook
     cd test-cookbook
    
  3. Create a recipe.

     chef generate recipe test-recipe #test-recipe is name of a recipe
     cd ..
    
  4. Write a code to install & deploy Apache server.

     #open vi editor to write the code in ruby language
     vi test-cookbook/recipe/test-recipe.rb
    
     package 'httpd' do
     action :install
     end
    
     file '/var/www/html/index.html' do
     content 'Apache server installed'
     action :create
     end
    
     service 'httpd' do
     action [:enable, :start]
     end
    
  5. Run the code.

     chef-client -zr "recipe[test-cookbook::test-recipe]"
    

That's all about today, I guess you and me both learnt something new today. Hope you find my notes easy to understand.