CHEF

In this section, we will cover the advantages of using Chef and a quick start guide for the same



Prerequisites
Familiarity with Ruby and underlying system.
WHAT IS CHEF?
CHEF is a configuration management tool written in Ruby and Erlang. It is used to configure and maintain a company's servers. (from Wikipedia's definition) "Chef helps you express your infrastructure policy – how your software is delivered and maintained on your servers – as code. When infrastructure is code, it becomes more maintainable, versionable, testable, and collaborative." -Chef's official documentation page. (Source: Chef learn-the-basics page)


Why Chef?


CHEF INSTALLATION
Use the following link: Link to install Chef DK to install the Chef development toolkit.
It has download and install options for different versions of Linux as well as Mac and Windows. It contains a set of tools needed to test your infrastructure. The following link can be used to download the Chef server: Link to download Chef server

A number of terms related to Chef are:



Chef Recipes: "A resource describes one part of the system and its desired state. A recipe is a file that holds one or more resources." (Definition from Chef basics page)

Chef Resources: "Each resource declares what state a part of the system should be in, but not how to get there. Chef handles these complexities for us." (Definition from Chef basics page)

The following steps are to be followed for the creation of Chef recipes and resources. The steps and contents of the files hello.rb, webserver.rb have been extracted from Chef basics page

Fig1. - Install curl on your Ubuntu 14.04 instance.

Fig2. - Install Chef on your Ubuntu 14.04 instance.

Fig3. - Create a chef directory and a file called hello.rb.


Your hello.rb file should have the following content:
file '/tmp/motd' do
content 'hello world'
end



Fig4. - Display contents of hello.rb and run the file.



Your webserver.rb file should have the following content:



Fig5. - Contents of webserver.rb file.


Fig6. - Run the webserver.rb file.

Fig7. - Run the webserver.rb file AGAIN.

Fig8. - View your sample website.


Chef Cookbooks:
"Cookbooks are said to be the fundamental unit of configuration." (Definition from www.digitalocean.com) Chef uses cookbooks to perform work and makes sure everything is running smoothly. The nodes on your system use the configuration details from your cookbooks.

We can now move on to the creation of cookbooks: (from www.digitalocean.com)
Go to your specific chef directory:
cd ~/chef-repo
Create a cookbook:
Install knife (command-line tool for Chef that could be a part of installation) knife cookbook create name_of_cookbook
Lets call it devops, so:
knife cookbook create devops
cd cookbooks/devops
ls
This will create a folder for your cookbook.

Sources