Configuration Management Tool
Configuration Management
Configuration management is a process similar to what administrators do
manually, here the same tasks are performed by initiating automation.
We are automating the configuration tasks by using configuration
management tools like Ansible, Chef, Puppet, Saltstack.
Here we are converting code into infrastructure.
Infrastructure as a code -> IAC
Since everything here is code we can test, repeat and we can apply version
control.
Features of Chef
Agent needs to be installed on each Chef Node
Relies on knife protocol for communication
Uses ruby language
Pull mechanism
Chef VS Ansible
Chef Architecture
Installation of Chef Workstation
Command:- wget https://packages.chef.io/files/stable/chef-
workstation/21.2.278/el/8/chef-workstation-21.2.278-1.el7.x86_64.rpm
Command:- yum -y install chef-workstation-21.2.278-1.el7.x86_64.rpm
Command:- chef --version (to verify chef package version installed)
Create your first Cookbook
Cookbook is a group of recipes and some other files and folders
Each cookbook defines a scenario
Create a new directory to keep all our cookbooks
Command:- mkdir cookbooks
Go inside the new directory and create a cookbook (Whatever commands are
going to be execute from here onwards, has to be executed under this new
cookbooks directory)
Command:- chef generate cookbook testcookbook
To view the list of all file and folders in tree format of the new cookbook use
Command:- tree testcookbook
Contents of a Cookbook
The following files and folders will be present under the Cookbook directory.
Chefignore – acts as .gitignore file. The files you want to ignore you can here.
Metadata.rb – this file consists of name, author, version…etc of a cookbook
Readme.rb – info about the usage of a cookbook
Recipe – where you write the ruby code to execute certain tasks
Spec – used for unit testing
Test – used for integration testing
Create your first Recipe
Be inside the Cookbooks folder created in earlier slide.
Command:- chef generate recipe testrecipe
vi cookbookname/recipes/ testrecipe.rb
file '/newfile1' do
content "Hello Vince!! testing our first recipe"
action :create
end
Run a Cookbook
To verify the code which you have written run the below command
Command:- chef exec ruby –c testcookbook/recipes/testrecipe.rb
You will get an output “SYNTAX OK” if the code is correct.
Apply that recipe locally to your machine as we didn’t setup Chef Node
machines yet.
Command:- chef-client -zr 'recipe[testcookbook::testrecipe]‘
Verify the file myfile is created under / directory or not by giving the below
command.
Command:- ls /
Create your second Recipe