Chef – A complete configuration tool

Chef – A complete configuration tool

Chef is a another powerful tool for configuration management which can ease Developers and Devops life. For setting up server and basis terminology refer link –

For learning chef and avoid costing we can skip setting up of chef server and can use hosted chef service by following simple steps –

• Sign up for a new account


  • Create an organization and download the starter kit.

  • Uncompressed the chef starter Kit and check for private key and knife.rb config file. In this wowdevops is oraganization name which I have created earlier and can be verified from chef server url parameter in knife.rb file.

# unzip

[email protected]:~/workdir/chef_dir# tree chef-repo/.chef/
├── knife.rb
└── vishal267.pem

0 directories, 2 files

[email protected]:~/workdir/chef_dir# cat chef-repo/.chef/knife.rb
# See for more information on knife configuration options

current_dir = File.dirname(__FILE__)
log_level :info
log_location STDOUT
node_name “vishal267”
client_key “#{current_dir}/vishal267.pem”
chef_server_url “”
cookbook_path [“#{current_dir}/../cookbooks”]


A recipe is most fundamental configuration element within the organization. it represent a piece of the system and its desired state. Recipe can

  • Install and configure software components
  • Manage files
  • Deploy applications
  • Execute other recipes

Resources in Recipe

Resources are the fundamental building blocks of chef configuration. They ensure the system is in the desired state. Few of resources are listed below.

  •  package: used to manage packages on a node
  • Service:  Used to manage services on a node
  • User: Manage users on the node
  • group: Manage groups
  • template: manage files with embedded ruby templates
  • cookbook_file: Transfer files from the files sub directory in the cookbook to a location on the node
  • file: Manage contents of a file on node
  • directory: Manage directories on node
  • execute: Execute a command on the node
  • cron: Edit an existing cron file on the node

Components of chef cookbook

A cookbook is like a package for chef recipes. it contains all the recipes,files, templates, libraries etc which are required to configure a portion of infrastructure .

Recipes are stored in cookbooks

Creating a simple cookbook

Cookbook for setup an apache webserver with a home page. It will include

  • Install apache Server on Ubuntu
  • Start the service and ensure that service will start when the machine boots
  • Write out the home page

Create a cookbook using chef generate command and check the directory structure using tree command.

Create a recipe with package, service and cookbook_file resource type. Also create an index.html in defaults directory under file directory.


Uploading the cookbook to chef hosted server

Bootstrapping the client node which will install chef-client on client machine

[email protected]:~/workdir/chef_dir/chef-repo# knife bootstrap IP –ssh-user ubuntu -i key.pem –sudo –node-name –yes –node-ssl-verify-mode none

Add Cookbook to node with name “” to node run list

Now Run chef client on Node machine which will install apache server.

[email protected]:~# chef-client
Starting Chef Client, version 14.10.9
resolving cookbooks for run list: [“apache::default”]
Synchronizing Cookbooks:
– apache (0.1.0)
Installing Cookbook Gems:
Compiling Cookbooks…
Converging 3 resources
Recipe: apache::default
* apt_package[apache2] action install
– install version 2.4.18-2ubuntu3.9 of package apache2
* service[apache2] action enable (up to date)
* service[apache2] action start (up to date)
* cookbook_file[/var/www/html/index.html] action create
– update content in file /var/www/html/index.html from ac5fd7 to 69c55a
— /var/www/html/index.html 2019-02-18 19:43:54.928659764 +0000
+++ /var/www/html/.chef-index20190218-18384-8uar0t.html 2019-02-18 19:43:58.508644441 +0000
@@ -1,376 +1,6 @@

Now check if index page is working or not. It working as expected.

[email protected]:~# curl localhost
<h1>Hello, world!</h1>

Leave a Reply

Your email address will not be published. Required fields are marked *