DevOps Classroom Series – Chef – 22/Nov/19

Visual Studio Code Configuration

  • Install Chef Extension into Visual Studio Code. Preview

Automating Deployments using Chef

  • Ensure you have manual steps/commands for whatever you want to automate.
  • Chef Organizes declarative syntaxes into
    • Cookbooks
      • Recipes
        • Resources

Chefs Basic Workflow for cookbook automation

Preview

Scenario-1: Install Git and tree

  1. Manual Execution (Ubuntu):
sudo apt-get update
sudo apt-get install git -y
sudo apt-get install tree -y
  1. Manual Execution (RedHat):
sudo yum install git -y
sudo yum install tree -y
  1. Creating a cookbook. For creating cookbook as part of chef dk installation, we get generators. Lets use cookbook generator
cd <starterkit-folder>\cookbooks\
chef generate --help
# since we want to generate cookbook
chef generate cookbook --help
# generate a cookbook called exercise1
chef generate cookbook exercise1 -b
  1. Observe the folder structure of exercise1 and you should be able to see default.rb in recipes folder which is default recipe.
  2. Refer Here for Chef Resources
  3. Basic Resource syntax is
<resource type> '<name of resource>' do
  property1 value1
  ..
  ..
  propertyn valuen
  action <some actions>
end
  1. Upload the cookbook. Uploading the cookbook in this case will be done using a tool called berkshelf (berks).
cd <starterkit>\cookbooks\<cookbook>
berks install
berks upload 
  1. Applying cookbook to node. In chef every node will have list of recipes to be executed. This list is called as run_list. Go to your node and change the run_list and add your recipe. Preview

Preview

  1. Once recipes are added to run list wait for Convergence. In this lets manually force Convergence. Login into node and execute chef-client

Leave a Reply

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

About continuous learner

devops & cloud enthusiastic learner