Configuration Mangement(CM) in Chef
- To do CM ensure (Are aware of manual way)
- You are aware of all the prerequisite softwares to be installed.
- You have a list of commands to be executed to deploy the application
Hello-World Chef Scenario
-
As of now we have a Lab setup
-
Now Scenario is
- We want all of our chef-client nodes to have the following softwares installed
- tree
- git
- elinks
- We want all of our chef-client nodes to have the following softwares installed
-
Commands for installing the above on
- Ubuntu:
sudo apt-get update sudo apt-get install git -y sudo apt-get install tree -y sudo apt-get install elinks -y
- Centos:
sudo yum install git -y sudo yum install tree -y sudo yum install elinks -y
-
To develop cookbooks we will be using visual studio code
-
Workflow to be followed in Chef:
- Generate a cookbook if required or else use the existing cookbook
- Generate a recipe or use the existing recipe
- Find a chef resource for every linux command you have noted (as above)
- Test whether the recipe (or the changes) are working or not
- upload the Cookbook to Chef Infra Server
- make changes if necessary to the run list of the nodes and wait for convergance
-
How to realize the above workflow
- To generate a cookbook, when we install chefdk on workstation we get generators and we can generate using command. Navigate to chef-repo and with in chef-repo you have cookbooks folder cd into that
cd C:\DevOps\Chef\Apr20\chef-starter\chef-repo\cookbooks chef generate --help chef generate cookbook --help chef generate cookbook helloworld -b
-
To generate a recipe in the cookbook use the command
chef generate recipe --help
. But in this scenario, i will be using a default recipe called as default.rb already generated with cookbook ![Previewhttps://directdevops.blog/wp-content/uploads/2020/04/chef25.png) -
To find the resource Naviagate to here and find the resources in the highlighted section as shown below
- Easier way to do this is understand resources syntax and then google
- Resource syntax
<resource type> 'name' do attribute 'value' action :action_type end
- Resource example:
file 'readmeattempt' do path '/home/ubuntu/test/readme.txt' action :create end
- Now if you want to find resource easily google ‘<linux command> in chef’ for example ‘yum in chef’
-
My default.rb looks as shown below
# # Cookbook:: helloworld # Recipe:: default # # Copyright:: 2020, The Authors, All Rights Reserved. # install git yum_package 'git' do package_name 'git' action :install end
5. Now i will upload the cookbook to chef server
cd helloworld berks install berks upload
- Navigate to manage.chef.io and login
- Now edit run lists
- Now wait for convergance on the node or manually force converge
sudo chef-client
Dev IDE Setup
- Open the folder with visual studio code
- Navigate to extensions
- Search for chef and install