DevOps Classroom Series – 03/Nov/2021

Just enough Ruby for Chef

  • Refer Here for the official docs from chef
  • Local variables
x = 1 # number
y = 'hello' # string
z =  "hai" # string
  • Embed a ruby variable in a string
topic = 'chef'
'Hello all, Welcome to #{topic}'
"Hello all, Welcome to #{topic}"

  • True and false (boolean)
  • Arrays
  • White space Arrays: This is shortcut for creating arrays without quotes and commas
  • Hash:
  • Conditional Statement using if else:
if <condition>
    # if block
elsif <condition>
    # else if block
else
    # else block
end

  • Looping using each
%w(redhat ubuntu).each do |osname|
  puts(osname)
end
  • Other useful statements

Chef contd..

  • Now lets try to apply whitespace array to array for package names in the apache_phpinfo cookbook Refer Here for the change set
  • Now apply the kitchen convergence and verify if everything works or not
  • Now our aim is to ensure this cookbook works for redhat instances also. The manual steps are
sudo yum install httpd -y
sudo systemctl enable httpd
sudo systemctl start httpd
sudo yum install  php php-mysql php-fpm -y
echo "<?php phpinfo(); ?>" | sudo tee /var/www/html/info.php
sudo systemctl restart httpd
  • When we want to run the recipe on different distributions of linux we should have a way to identify the way to find the information about the node on which recipe is executing.
  • For doing this in chef there is tool called as ohai which gets installed on the node and informs the chef server about the details of the node

Leave a ReplyCancel reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.

Please turn AdBlock off
Social Network Integration by Acurax Social Media Branding Company

Discover more from Direct DevOps from Quality Thought

Subscribe now to keep reading and get access to the full archive.

Continue reading

Exit mobile version
%%footer%%