DevOps Classroom Series – 22/Apr/2020


  • Our organization uses chef to deploy medical record application

  • For that we have

    • Dev Environment
    • System Testing ENV (ST)
    • Load Testing ENV (LT)
    • Pre-Production ENV (Pre-PROD)
    • Production ENV
  • Architecute: Preview

  • Since we deploy with chef the Infrastructure look as shown below Preview

Practical Problems & Solutions

  1. For the application server i want convergance to happen every 60 minutes and for database i want convergance to happen every 24 hours

    • Use a supermarket cookbook called as chef-client Preview Preview
    • Add depends statement to tomcat cookbook and also to postgres cookbook
    • Navigate to attributes/default.rb (create if not present) and add the following line
    default['chef_client']['interval'] = 3600 # for tomcat
    default['chef_client']['interval'] = 86400 # 
    • Add chef_client to the run_list of appserver and db server
  2. You Dev Team is using Java 8 for application server now, they want to move from Java 8 to Java 11 in the new version which will be first tested by Dev then testing and after that released to customers

    • For the application server in various environments the run_list is same and when i upload a new version of cookbook it will be impacting all the environments
    • To solve this problem, chef has a concept called as environments. Refer Here
    • Environment is chef’s way of mapping real-world environments to chef infra structure. All the nodes in chef will have some environment. All these days we ignored (_default). Preview
    • Chef Environment is all about
      1. putting restrictions on which version of cookbook has to applied
      2. For this environment what will be attribute value
    • Create two envs dev and qa and add generate a cookbook appserver with two versions 1.0.0 & 1.1.0 with some changes in recipe’s resources. dev should have the restriction of ‘appserver ~= 1.1.0’ and qa should have restriction of ‘appserver = 1.0.0’
    • Now add app server to run list of both the servers and if you look at ui it looks as shown below Preview Preview
    • Solution is to use environments
    • For creating environments from file refer here for formats and for management
  3. You have 5 environments in which you have appserver and they have the same runlist and different environment and for dbserver you have to maintain the same runlist

    • Why i should i do the same thing multiple times? and chef has a solution this with chef roles refer here
    • Chef role is all about generalizing run_lists and setting attributes
    • Create a role called as appserver and define what should be its run_list and also dbserver role and defind what should be run_list of db servers
    • Now navigate to nodes and change the run_lists from individual recipes to roles Preview Preview
  4. How to maintain secrets in Chef?

    • In chef the secrets like passwords can be maintained using encrpytion by a concept called as Databags.
    • Attribute is maintained at cookbook level and can be changed in
      • Recipe
      • Role
      • Environment
    • Whereas Databag is stored at the chef server level which means it is shared to all the cookbooks
    • Refer Here for official docs
    • Follow what has been done in class
    • To access the decrypted value inside recipes use the following syntax Refer Here
    data_bag_item('<databag Name>', '<item name>', '<secret>')
  5. How is chef used mostly in Cloud-Enabled or Virtual-Enabled Enterprises?

  6. How to fail chef cookbook execution?

    • the script in recipe looks as shown below
if <some unsupported> do
   raise 'error message'
  1. Where does chef server stores cookbooks?
    • INternally has Postgres db and a rabbit mq
    • Chef has a component designed which is called as bookshelf to store cookbooks in servers
  2. I have thousands of servers, do i need to bootstrap all of the manually?

Leave a Reply

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

About learningthoughtsadmin