DevOps Classroom Series – 28/May/2021

Installing apache server on ubuntu

  • Launch a ubuntu VM
  • Login into the VM and execute the following commands
sudo apt update
sudo apt install apache2 -y
  • Verify the installation by navigating to public IP Preview
  • Verify the installation from command line Preview

Lets do this in Chef

  • Now lets try to create a cookbook in chef which automates the above activity

  • We need a cookbook:

    • Navigate to chef-repo\cookbooks folder Preview
    • Lets create a chef cookbook Refer Here Preview Preview Preview
    • I will be creating a cookbook for installing apache using the following
    chef generate cookbook myapache -b --chef-license accept


  • A new directory will be created. will have some files and folders

  • Chef is developed using ruby language. Chef has its own DSL (Domain Specific Language). If required we can directly use ruby in chef cookbooks.

  • Launch the cookbook in visual studio code, install chef extension Preview

  • Now execute the command berks install Preview

  • In Chef cookbook there is already a recipe created called as default (recipes\default.rb)

  • In chef recipe we will be using resources to automate the manual steps Preview Preview

  • The resources in chef will have following syntax

<resource type> 'name' do 
   property1 value1
   propertyn valuen
   action <action to acheive>
  • In recipes\default.rb

apt_update 'ubuntu packages' do
  action :update

# sudo apt install apache2 -y
apt_package 'apache2' do
    action :install

  • Now upload the recipe to the chef server
berks upload


  • Once the cookbook is uploaded, we need to specify to chef server on which nodes should the recipes be executed. Preview

  • Now we need to change the nodes run_list Preview Preview Preview

  • Do this for the other ubuntu node

  • Now we can wait till the nodes query the server about the work that needs to be done (Convergence)

  • For lab purposes lets manually force the convergence

    • login into the node & execute sudo chef-client Preview Preview
  • Creating and making cookbooks work is the major activity in the cookbook development

  • Uploading cookbook to the server adding it to run_list etc can be done once our cookbooks are working.

  • Next Steps:

    • Becoming good at writing cookbooks
    • Local development of cookbooks, testing them and upload right versions to server


  • Cookbook is fundamental unit of configuration and distribution in chef.
  • A cookbook defines a scenario and contains everything needed to support that scenario
    • Recipe
    • Attributes
    • Files
    • Templates
    • Custom Resources

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.

About learningthoughtsadmin