DevOps

LAB 3: Installing and Configuring Chef

DevOps

LAB 3: Installing and Configuring Chef

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 /