DevOps Classroom Series – 20/Nov/2021

Chef Cookbooks With Chef Server

  • Lets bootstrap two nodes to the hosted chef server
  • 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
    • Now lets login into ubuntu node 1 and manually force convergance
    • 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
    • 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,
  • 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
  • Now lets apply the same runlist of experiment to ubuntunode1 and ubuntunode2.
  • Now lets make the ubuntunode1 environment => dev and ubuntunode2 environment => prod
  • converge results of ubuntunode1
  • converge results of ubuntunode2

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
  • Now lets add the roles
    • webserver+dbserver to the run_list of ubuntunode1
    • webserver to the run_list of ubuntunode2
  • Now lets manually force the convergence
    • ubuntu node1: => webserver+dbserver
    • ubuntu node2: => webserver

Leave a comment

Turn on JavaScript to leave a comment.

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

Please turn AdBlock off
Social Media Widget Powered by Acurax Web Development Company
Exit mobile version
%%footer%%