DevOps Classroom Series – 08/Jan/2021

Bootstrapping one more node

  • Lets create a centos 7 machine in azure and bootstrap the node into chef server Preview Preview Preview Preview
  • In yesterday’s class we have downloaded chef starter kit, whenever starter kit is downloaded a new key pair is generated for authentication. so if you try running commands from the chef-repo extracted from older download the commands will fail.
  • As of now our chef configurations are as shown below Preview
  • Since nodes are bootstrapped, nodes will communicate to the server periodically by default for every 30 mins to ask about what has to be executed. This communication is referred as Convergance
  • In Chef when we upload cookbooks to chef server and configure it run on nodes. Chef nodes will not run them immedietly, they will automatically run during next convergance. So this might lead to situations where your desired state is not the actual state till the convergance is executed. This state is called as Configuration Drift

Chef Cookbook Development and Node Configuration workflow

  • Lets assume we want to install apache server on nodes using chef
  • So to do this in Chef we need to generate a cookbook
    • Navigate to chef repo and cookbooks folder Preview
    • In this folder we need to generate chef cookbook and when we install chefdk we get generators installed
    chef generate --help
    chef generate cookbook --help
    
    Preview Preview
    • Now lets generate cookbook using the following command
    chef generate cookbook -b my_first_cookbook 
    
    Preview Preview Preview Preview
    • In the recipes folder there will be a file called as default.rb which is a default recipe.
    • Now in chef the file extensions for recipe’s will be .rb i.e. this is a ruby file.
    • Chef is developed using ruby, To work with chef , chef has its own DSL or you can directly write ruby.
    • Now lets create a recipe called as centos_apache Preview Preview Preview Preview
    • Now lets create a recipe called as ubuntu_apache Preview Preview
    • In this recipes we need to write something to express our desired state. To express this desired state we need to understand Recipe DSL (Domain Specific Language ) Refer Here
    • In chef recipes we will have to use chef resources. Refer Here
    • Resource will be in the following format
    resourcetype '<name of the resource>' do
      attribute1 'value1'
      attributen 'valuen'
      action :type_of_action
    end
    
    • To write these resources effectively, we need to understand the manual configurations steps of your desired state
      • ubuntu to install apache
      sudo apt-get update
      sudo apt-get install apache2 -y
      
      • centos to install apache
      sudo yum install httpd
      sudo systemctl enable httpd.service
      sudo systemctl start httpd.service
      
    • Now the next step is to convert each command in the installation/configuration step to equivalent chef resource.
    • In todays class lets use chef resource to create an empty file in /tmp/myfirstfile.txt
    • Refer Here for all the resources
    • In recipes\default.rb write the following content
    file '/tmp/myfirstfile.txt' do
      action :create
    end
    
    • now in the commmand line of cookbook folder execute two simple commands
    berks install 
    berks upload
    
    Preview
    • Now navigate to manage.chef.io Preview Preview
  • Next Steps:
    • How to add the recipes to execution during convergance.
    • Chef developer environment setup
    • Chef cookbook for apache installations

Leave a Reply

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

About learningthoughtsadmin