DevOps Classroom Series – 20/Nov/2021

Chef Cookbooks With Chef Server

  • Lets bootstrap two nodes to the hosted chef server Preview
  • Experiment:
    • Develop a simple cookbook with version 1.0.0 which prints this is version 1.0.0
    • use log resource Refer Here
    • Refer Here for the new cookbook added.
    • Now upload the recipe and this to the run_list of the ubuntunode1 Preview
    • Now lets login into ubuntu node 1 and manually force convergance Preview
    • Now lets assume we are giving uploading a new version of the cookbook (experiment 1.0.0) and this should not apply to ubuntunode1. ubuntunode1 should work with experiment with version 1.0.0
    • Refer Here for the new version of cookbook
    • Upload the new version and now login into ubuntunode1 and manually force convergence Preview
    • We need to have some kind of mechanism where we need to restrict the cookbook versions to be uploaded.
    • In Chef we can solve the problem with cookbook versions using Environments
    • Lets create three cookbooks
      • qtwebapp
        • default
        • configure
      • qtdbapp
        • default
        • configure
      • qtcommonapps
        • recipes:
          • default
          • special
    • Now lets assume we have three categories of nodes
      • We have db servers
      • We have web servers
      • For testing we have some nodes where we install both web and db on same node
    • To do this we need to have the following run_lists
      • webserver => qtcommonapps::default, qtcommonapps::special, qtwebapp::default, qtwebapp::configure
      • db server => qtcommonapps::default, qtdbapp::default, qtdbapp::configure
      • web+dbserver => qtcommonapps::default, qtcommonapps::special, qtwebapp::default, qtwebapp::configure,qtdbapp::default, qtdbapp::configure
    • When we have lot of servers to deal with creating run_lists like shown above does it make sense?
    • We need to have some kind of a solution to manage run_lists effectively
    • In Chef we can solve the problem with managing run_lists using Roles

Chef Environments

  • An environment is a way to map organization real-life workflow.
  • With Environments we can define the below and attach environment to the node
    • cookbook versions applicable
    • attributes
  • Chef has a default environment already defined _default where there are no restrictions, Preview
  • We can create environments like shown below and attach it to the node
    • DEV
    • QA
    • STAGING
    • PROD
  • There are two ways of creating environments,
    • Using Chef Managment console: Easy but not recommended
    • Create a file in the chef-repo and upload: In this we are having a file which represents environment and we can easily track all the changes done to a file which represents environment as we version control it.
  • Refer Here for the official documentation
  • Refer Here for the changeset.
  • Now lets try to upload environments knife environment from file Refer Here for documentation Preview Preview
  • Now lets apply the same runlist of experiment to ubuntunode1 and ubuntunode2.
  • Now lets make the ubuntunode1 environment => dev and ubuntunode2 environment => prod Preview
  • converge results of ubuntunode1 Preview
  • converge results of ubuntunode2 Preview

Roles

  • Role consists of run_list and attributes
  • To the nodes run_list we can add roles directly instead of individual recipes
  • To do this we need to have the following run_lists
    • webserver => qtcommonapps::default, qtcommonapps::special, qtwebapp::default, qtwebapp::configure
    • db server => qtcommonapps::default, qtdbapp::default, qtdbapp::configure
    • web+dbserver => qtcommonapps::default, qtcommonapps::special, qtwebapp::default, qtwebapp::configure,qtdbapp::default, qtdbapp::configure
  • Now first lets upload qtcommonapps, qtwebapps and qtdbapss. Refer Here for the changeset with all the three cookbooks
  • Now lets create the roles, As environments we can create using console and from file. Refer Here for the official docs
  • Refer Here for the changeset
  • Refer Here for the command to upload the roles to chef server Preview Preview
  • Now lets add the roles
    • webserver+dbserver to the run_list of ubuntunode1 Preview
    • webserver to the run_list of ubuntunode2 Preview
  • Now lets manually force the convergence
    • ubuntu node1: => webserver+dbserver Preview
    • ubuntu node2: => webserver Preview

Leave a Reply

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

Please turn AdBlock off
Social Network Widget by Acurax Small Business Website Designers

Discover more from Direct DevOps from Quality Thought

Subscribe now to keep reading and get access to the full archive.

Continue reading

Visit Us On FacebookVisit Us On LinkedinVisit Us On Youtube