DevOps Classroom Series – 09/Jan/2021

Chef cookbook workflow (Contd..)

  • Now the recipe which we uploaded should run on the nodes Preview
  • Chef server maintains list of recipes to be executed on each node which is called as run_list Preview
  • To this run_list we need to add recipes the recipe is denoted as
hellochef::default => hellochef
  • when we just add cookbook name to the run_list chef server will automatically add ::default to it
  • Now lets change the run_list for both the nodes Preview Preview Preview
  • Repeat same steps for other node
  • At this moment we can wait till the next convergance for the run_list to get executed. But for the purpose of this class we will manually force convergance
    • Login in the node
    • Execute the following command sudo chef-client
  • AWS Node manual convergance Preview Preview Preview Preview
  • Azure Node manual convergance Preview Preview
  • Now lets draw the cookbook developement process
    • Get the list of manual steps for automating configuration
    • For each step try to find chef resource and express the desired state in a recipe
    • Now upload the chef cookbook
    • Add the recipe’s to the run-list on the nodes where you would like to apply configuration
  • But lets try to get little bit deeper into this
    • Will all cookbooks developed will be running correct all the time in the first run? No
    • Is it possible for us to modify the run_list every time during development of cookbooks? No
  • So lets look at one scenario. There is a new requirement to create one more file in aws and azure nodes /tmp/Readme.txt Preview Preview
  • Since it skips we need to change the version of cookbook in metadata.rb file Preview Preview
  • So everytime we make changes we need to change the version of cookbook, so if we follow this approach, we might have some versions of cookbooks in chef server which can have errors.
  • So chef simplifies cookbook development, by suggesting a developer environment using Test Kitchen
  • Using Test Kitchen we can create test nodes, run the cookbooks and only if the cookbook is working as expected upload the cookbook to chef server.

Cookbook Development Environment

  • Initially lets focus on developing chef cookbooks and verifying, So we dont need chef server and nodes till we do this
  • We need to create test environment for checking our cookbooks. Test Kitchen can create test environments using
    • vagrant (local vms)
    • AWS
    • Azure
    • Docker
  • We can execute kitchen command to verify the cookbooks
  • All of this is done from one simple configuration file in the cookbook called as kitchen.yaml Preview
  • To understand yaml and json formats watch the video Refer Here
  • To develop cookbooks we can use any text editor, in this class we will be using visual studio code Preview Preview
  • Next Steps

Leave a Reply

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

About learningthoughtsadmin