DevOps Classroom Series – 11/Apr/2020

Configuration Mangement(CM) in Chef

  • To do CM ensure (Are aware of manual way)
    • You are aware of all the prerequisite softwares to be installed.
    • You have a list of commands to be executed to deploy the application

Hello-World Chef Scenario

  • As of now we have a Lab setup Preview

  • Now Scenario is

    • We want all of our chef-client nodes to have the following softwares installed
      • tree
      • git
      • elinks
  • Commands for installing the above on

    • Ubuntu:
    sudo apt-get update
    sudo apt-get install git -y
    sudo apt-get install tree -y
    sudo apt-get install elinks -y
    • Centos:
    sudo yum install git -y
    sudo yum install tree -y
    sudo yum install elinks -y
  • To develop cookbooks we will be using visual studio code

  • Workflow to be followed in Chef:

    1. Generate a cookbook if required or else use the existing cookbook
    2. Generate a recipe or use the existing recipe
    3. Find a chef resource for every linux command you have noted (as above)
    4. Test whether the recipe (or the changes) are working or not
    5. upload the Cookbook to Chef Infra Server
    6. make changes if necessary to the run list of the nodes and wait for convergance
  • How to realize the above workflow

    1. To generate a cookbook, when we install chefdk on workstation we get generators and we can generate using command. Navigate to chef-repo and with in chef-repo you have cookbooks folder cd into that
    cd C:\DevOps\Chef\Apr20\chef-starter\chef-repo\cookbooks
    chef generate --help
    chef generate cookbook --help
    chef generate cookbook helloworld -b

    Preview Preview Preview Preview

    1. To generate a recipe in the cookbook use the command chef generate recipe --help. But in this scenario, i will be using a default recipe called as default.rb already generated with cookbook ![Preview

    2. To find the resource Naviagate to here and find the resources in the highlighted section as shown below

      • Easier way to do this is understand resources syntax and then google
      • Resource syntax
      <resource type> 'name' do 
          attribute 'value'
          action :action_type
      • Resource example:
      file 'readmeattempt' do
          path '/home/ubuntu/test/readme.txt'
          action :create
      • Now if you want to find resource easily google ‘<linux command> in chef’ for example ‘yum in chef’ Preview Preview
    3. My default.rb looks as shown below

    # Cookbook:: helloworld
    # Recipe:: default
    # Copyright:: 2020, The Authors, All Rights Reserved.
    # install git 
    yum_package 'git' do
        package_name 'git'
        action :install

    Preview 5. Now i will upload the cookbook to chef server

    cd helloworld
    berks install 
    berks upload
    1. Navigate to and login Preview
    2. Now edit run lists Preview Preview
    3. Now wait for convergance on the node or manually force converge sudo chef-client Preview

Dev IDE Setup

  • Open the folder with visual studio code
  • Navigate to extensions Preview
  • Search for chef and install Preview

Leave a Reply

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

About learningthoughtsadmin