DevOps Classroom Series – 28/Aug/2020

Bootstrapping one more node

  • This time lets create a ubuntu node from azure Refer Here for creating a vm in azure Preview
  • Now lets bootstrap this node by using knife command
knife bootstrap -U qtdevops -P motherindia@123 --sudo -N azurenode


  • Lets look at node list from command line and ui Preview Preview

Lets create a simple workflow to install git on all of our nodes

  • Working Principles:
    1. Before we try to automate any thing in chef, first get to know the manual way of doing it.
    2. Make a list of the commands you need to execute for your application deployment
  • How to work the above in chef:
    • In chef to automate the deployment we create cookbooks
      • In this case let me call this as utility cookbook
      • Navigate to your chef-repo/cookbooks folder in the terminal
      • To generate a cookbooks, when we install chefdk, we get a command line tool called as chef. This tool chef has a sub command called as generate
      chef generate --help
      chef generate cookbook --help
      Preview Preview
      • From the above documentation our command will be
      chef generate cookbook utility
      • When we generated the cookbook we got some files and folders as shown below Preview
  • Cookbook: cookbook defines a scenario (application deployment) and contains everything that is required to automate the scenario
  • We have already understood that cookbook is collection of recipes & many other things, but lets focus on recipes
  • In the generated cookbook there is already a folder called as recipes and there is file called as default.rb Preview
  • In chef, we write all of recipes inside the recipes folder & the default recipe is default.rb file.
  • So recipe will be a .rb file inside recipes folder in a cookbook.
  • Chef uses ruby and .rb stands for ruby file. Inside recipes you can use a custom language (DSL) developed by chef or plain ruby.
  • We understood that recipe is resources written in a specific order.
  • How to write a resource & what is resource
    • Resource is smallest unit of automation in chef where you can describe the desired state
    • The resource syntax in chef is
    <resource_type> 'resource name' do
       <property-1> <value-1>
       action <action to be performed>
    • Example of chef resource
    service 'apache2' do
      action :restart
  • The manual commands to install git on ubuntu
sudo apt-get update
sudo apt-get install git -y
  • For every manual command try to find a chef resource.
    • The easiest way to find a resource is google the pattern of search is apt-get update in chef Preview
    • Open the documentation and look at the highlighted sections Preview
    • The resource code in the recipes/default.rb
    apt_update 'update ubuntu packages' do
        action :update
    • Now lets find a resource for apt-get install git Preview Preview
    • Now the recipes/default.rb will be as shown below
    # Cookbook:: utility
    # Recipe:: default
    # Copyright:: 2020, The Authors, All Rights Reserved.
    apt_update 'update ubuntu packages' do
        action :update
    apt_package 'git' do
        action :install
  • Now we need to upload cookbook to chef server. The steps for doing that is Refer here
knife cookbook upload --help
knife cookbook upload utility


  • Now verify the cookbook in Preview
  • Since the cookbook is uploaded, we need to inform chef server on which nodes this recipe should be executed. Chef does this by a concept called run_list. Consider run_list to be a list of recipes to be executed on the node. In chef every node will have one run_list.
  • Select the node on the Server UI and edit the run_list Preview Preview
  • Now chef server will execute this cookbook during next convergence. For this session, lets manually force converge. Login into the node and execute
sudo chef-client


Leave a Reply

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

About learningthoughtsadmin