DevOps Classroom Series – 03/Dec/2019

Scenario

  • Important info:
    • By default chef always picks the latest version of cookbook Preview
  • All the nodes are deployed using
    • tomcat cookbook
      • version 1.0.0
      • java => 8
  • Now you have been asked to change the following
    • JDK8 to JDK9
    • tomcat7 to tomcat8
  • Ideally you should be making changes to QA Servers first and then to Production
  • Now lets assume you have changed tomcat cookbook to install tomcat8 and jdk9 with version 1.1.0
  • During next convergance all the servers will get update with 1.1.0 which can be a disaster
  • For this in chef we have concept called as Environments
  • Environment impose restrictions on cookbook versions.
  • It is necessary that every node belongs to one environment. The default environment is _default.
  • To solve the above problem
    • Create a new environment called as QA
      • tomcat = 1.1.0
    • Create a new environment called as Prod
      • tomcat = 1.0.0 Preview

Sample with Environments and Roles

  • Create a simple cookbook with name envroledemo
  • In the first version 1.0.0 write some resources. In this series i will be using file resource to create a file with some content
  • Recipe => java in 1.0.0
file '/home/ubuntu/java' do
    content 'jdk8'
    action :create
end
  • Recipe => java in 1.1.0
file '/home/ubuntu/java' do
    content 'jdk9'
    action :create
end
  • Creating Roles: Roles can be created
    • On Chef Manage UI
    • From ruby or json files in Starter Kit.
  • Refer Here for role formates
  • In this series i prefer ruby files. I have create a tomcat.rb file in roles folder with following content
name "tomcat"
description "tomcat role"
run_list "recipe[envroledemo::java]"

Leave a Reply

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

About continuous learner

devops & cloud enthusiastic learner