Chef Basics /Installation and Configuration

Cloud Passion
3 min readJan 8, 2020

Chef is used in infrastructure automation and helps in reducing manual and repetitive tasks for infrastructure management.

Uses Ruby encoding to develop basic building blocks like recipe and cookbooks.

Why Chef ?

a) used to automate the infrastructure provisioning

b) streamline the task of configuration and managing the company’s server.

c) capability to get integrated with any of the cloud technology.

d) does not make assumptions on the current status of a node. It uses its mechanisms to get the current status of machine.

Major Throwback

It needs constant babying so that people who are working should not mess up with others cookbooks.

Components of Chef

a)Attribute

They are settings stored in form of key-value pair — they are used to change the existing state or setting a particular infrastructure node

b) Recipe

collection of attributes which are used to manage the infrastructure.

They are loaded during Chef client run and compared with the existing attribute of the node and relevant action is taken

c) cookbook

collection of recipes . They are the basic building blocks which get uploaded to Chef server

d) Resource

It is the basic component of a recipe used to manage the infrastructure with different kind of states

There can be multiple resources in a recipe, which will help in configuring and managing the infrastructure. Some of common examples are package/service/user/group/template /file/directory

e) Metadata

It is used to manage the metadata about the package. This includes details like the name and details of the package. It also includes things such as dependency information that tells which cookbooks this cookbook needs to operate

f) Files

It’s a sub-directory within the cookbook

How Chef works ?

It is 3 tier client server model

a) Cook books are developed on chef workstation , (Usually a local machine )Work stations are installed command line utilities like knife , test kitchen

b) Knife help to upload cookbooks to Chef Server

c) All Chef nodes on which cookbook needs to be installed are registered to chef Server

Chef Node Components

Chef client is the key component of all the nodes, which helps in setting up the communication between the Chef server and Chef node . Install this at each node

Ohai — helps in getting the current state of any node at a given point of time.

Starting with Chef

Step 1 : Install Chef development kit in you host . Check if this is working via firing command

chef -v

You can use it locally or on a AWS/GCP . I am focusing on first approach by using it with Virtual Box and Vagrant , both of which are well known virtualization tools.

check if virtual box is installed

vboxmanage — version

Check if vagrant is installed

vagrant — version

Create a centos machine in vagrant using virtualbox

vagrant box add bento/centos-7.2 — provider=virtualbox

Bento is basically a chef project which provides baseline machines for chef development

Do vagrant init to start these vm

vagrant init bento/centos7.2 ; vagrant up

It will create a configuration file VagrantFile inside your current directory

This file is used to launch and manage your instance.

Connect to your machine via vagrant ssh (running vagrant up in logs will give ip to connect to) Now you can install chef development kit (cdk) inside it.

For RHEL 7 you can use following commands

wget https://packages.chef.io/files/stable/chefdk/4.6.35/el/7/chefdk-4.6.35-1.el7.x86_64.rpm

rpm -ivh chefdk-4.6.35–1.el7.x86_64.rpm

Chef also needs ruby to be installed . You can find the tutorial here for same

Once both are installed correctly you can check if both are installed correctl via using

which chef

which ruby

If everything works fine congrats you are now ready to write cookbooks

--

--

Cloud Passion

I‘m a Software Engineer by profession, but an Entrepreneur by passion. I have specialization in Cloud and Devops Concepts like Docker,k8,helm,chef,ansible etc