What is Chef Recipe?
A recipe is the most fundamental configuration element within the organization. A recipe:
- Is authored using Ruby, which is a programming language designed to read and behave in a predictable manner
- Is mostly a collection of resources, defined using patterns (resource names, attribute-value pairs, and actions); helper code is added around this using Ruby, when needed
- Must define everything that is required to configure part of a system
- Must be stored in a cookbook
- May be included in another recipe
- May use the results of a search query and read the contents of a data bag (including an encrypted data bag)
- May have a dependency on one (or more) recipes
- Must be added to a run-list before it can be used by Chef Infra Client
- Is always executed in the same order as listed in a run-list
yum_package 'httpd' do | |
action :install | |
end | |
file 'index.html' do | |
content "Hello everyone from DevOpsSchool" | |
end | |
cookbook_file '/var/www/html/index.html' do | |
source "index.html" | |
action :create | |
end | |
service 'httpd' do | |
action :start | |
end | |
bash 'extract_module' do | |
code <<-EOH | |
cp index.html /var/www/html/index.html | |
EOH | |
end |
node.default['main']['doc_root'] = "/vagrant/web" | |
execute "apt-get update" do | |
command "apt-get update" | |
end | |
apt_package "apache2" do | |
action :install | |
end | |
service "apache2" do | |
action [ :enable, :start ] | |
end | |
directory node['main']['doc_root'] do | |
owner 'www-data' | |
group 'www-data' | |
mode '0644' | |
action :create | |
end | |
cookbook_file "#{node['main']['doc_root']}/index.html" do | |
source 'index.html' | |
owner 'www-data' | |
group 'www-data' | |
action :create | |
end | |
template "/etc/apache2/sites-available/000-default.conf" do | |
source "vhost.erb" | |
variables({ :doc_root => node['main']['doc_root'] }) | |
action :create | |
notifies :restart, resources(:service => "apache2") | |
end |





I’m a DevOps/SRE/DevSecOps/Cloud Expert passionate about sharing knowledge and experiences. I am working at Cotocus. I blog tech insights at DevOps School, travel stories at Holiday Landmark, stock market tips at Stocks Mantra, health and fitness guidance at My Medic Plus, product reviews at I reviewed , and SEO strategies at Wizbrand.
Please find my social handles as below;
Rajesh Kumar Personal Website
Rajesh Kumar at YOUTUBE
Rajesh Kumar at INSTAGRAM
Rajesh Kumar at X
Rajesh Kumar at FACEBOOK
Rajesh Kumar at LINKEDIN
Rajesh Kumar at PINTEREST
Rajesh Kumar at QUORA
Rajesh Kumar at WIZBRAND