🚀 DevOps & SRE Certification Program 📅 Starting: 1st of Every Month 🤝 +91 8409492687 🔍 Contact@DevOpsSchool.com

Upgrade & Secure Your Future with DevOps, SRE, DevSecOps, MLOps!

We spend hours scrolling social media and waste money on things we forget, but won’t spend 30 minutes a day earning certifications that can change our lives.
Master in DevOps, SRE, DevSecOps & MLOps by DevOpsSchool!

Learn from Guru Rajesh Kumar and double your salary in just one year.


Get Started Now!

Chef Tutorials: Example of Chef Recipe Program

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
view raw first.rb hosted with ❤ by GitHub
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
view raw recipe.rb hosted with ❤ by GitHub
Subscribe
Notify of
guest


0 Comments
Newest
Oldest Most Voted
Inline Feedbacks
View all comments
reCaptcha Error: grecaptcha is not defined

Certification Courses

DevOpsSchool has introduced a series of professional certification courses designed to enhance your skills and expertise in cutting-edge technologies and methodologies. Whether you are aiming to excel in development, security, or operations, these certifications provide a comprehensive learning experience. Explore the following programs:

DevOps Certification, SRE Certification, and DevSecOps Certification by DevOpsSchool

Explore our DevOps Certification, SRE Certification, and DevSecOps Certification programs at DevOpsSchool. Gain the expertise needed to excel in your career with hands-on training and globally recognized certifications.

0
Would love your thoughts, please comment.x
()
x