How to Install Chef in Linux Server Using AWS

Follow the steps:

• Go to
• Go to Downloads
• Click on Chef Workstation
• Go to Red Hat Enterprise Linux
• Copy url of RHEL – 7

• wget
• yum install chefdk-3.0.36-1.el7.x86_64.rpm -y      

• Verify Chef installation

• chef -v
• chef --version


Cookbook is a group of recipes and some other files & folders
• Each cookbook defines a scenario.

• Eg: web server cookbook   

• Create a new directory (Don’t change the name of directory)

• mkdir cookbooks 

• Go inside & create a cookbook (Whatever you do, do inside cookbooks folder)

• chef generate cookbook test-cookbook
• tree test-cookbook

Inside Cookbook??

Chefignore : like .gitignore
Kitchen.yml: for a testing cookbook
• Metadata.rb : name, author, version ..etc… of cookbook
• : info about usage of cookbook
• Recipe: where you write code
• Spec: for unit test
• Test: for integration test

Create your first Cookbook & Recipe

• Already created cookbook (test-cookbook)
• Go inside the test-cookbook(But not inside recipes folder) & Create a recipe

• chef generate recipe test-recipe

• vi test-cookbook/recipes/test-recipe.rb

file ‘/myfile’ do
content ‘Hello Dear Students!!’
action :create

• To Verify the code(be inside cookbooks folder)

• chef exec ruby -c test-cookbook/recipes/test-recipe.rb

• Apply that recipe locally(be inside cookbooks folder)

• sudo chef-client -zr “recipe[test-cookbook::test-recipe]”

• Verify

• ls /

Create & Write your Second Recipe

• Go inside the cookbook(But not inside the recipes folder)& Create a recipe

• chef generate recipe demo-recipe

• vi test-cookbook/recipes/demo-recipe.rb

package ‘tree’ do
action :install
file ‘/myfile2’ do
content ‘This is my second file’
action :create
owner ‘root’
group ‘root’

• Apply that recipe locally(be inside cookbooks folder)

• sudo chef-client -zr “recipe[test-cookbook::demo-recipe]”

• Verify

• ls /
• which tree

• Code execution is from left to right & top to bottom.

Leave a Reply

Your email address will not be published. Required fields are marked *