DevOps - Lab 3: Installing and Configuring Chef
Installing and Configuring Chef
In Lab 3: Installing and Configuring Chef, participants typically focus on the installation and initial setup of Chef, an automation platform used for configuring and managing infrastructure as code. This lab involves installing the Chef Workstation on the local machine and configuring essential settings such as user credentials and organizational details. Participants may also explore the deployment of the Chef Infra Server, which acts as the central hub for storing and managing cookbooks and configurations. The lab aims to provide hands-on experience in setting up the Chef environment, enabling participants to automate infrastructure provisioning and configuration. Successful completion of Lab 3 equips participants with the foundational skills required to leverage Chef for streamlined and consistent infrastructure management within their DevOps workflows.
Lab:
Step 1. Go to chef.sh —-> Downloads
Step 2. Click on Chef Workstation
Step 3. Go to Red Hat Enterprise Linux/CentOS
Step 4. Copy URL of Red Hat Enterprise Linux/CentOS 7
wget https://packages.chef.io/files/stable/chef-workstation/0.16.33/el/7/chef-workstation-0.16.33-1.el7.x86\_64.rpm
yum install chefdk-3.0.36-1.c17.x86\_64.rpm –y
Step 5. Verify Chef Installations
chef –v
chef -- version
Step 6. Generating a Cookbook
- Cookbook is a group of recipes and some other files and folders
- Each cookbook defines a scenario
- Create a new directory (Don’t change the name of the directory)
- Go inside & create a cookbook (Whatever you do, do inside cookbooks folder)
mkdir cookbooks
cd cookbooks
chef generate cookbook test-cookbook
ls
tree test-cookbook
Step 7. Components of Cookbook
- Chefignore: like .gitignore
- Kitchen.yml: for testing cookbook
- Metadata.rb: name, author, version, etc…of cookbook
- Readme.md: info about usage of cookbook
- Recipe: Where you write code
- Spec: For unit test
- Test: For integration test
- Chef Supermarket: Where you get custom code
Step 8. Generating a Recipe
cd test-cookbook
chef generate recipe test-recipe
cd ..
vi test-cookbook/recipes/test-recipe.rb
(Press i)
file ‘/myfile’ do
content “Welcome to RST Forum!!!”
action :create
end
(Press esc)
:wq!
Step 9. To verify the code
chef exec ruby –c test-cookbook/recipes/test-recipe.rb
Step 10. Apply that recipe locally
chef-client –zr “recipe\[test-cookbook::test-recipe\]”
ls /