DevOps Classroom Series – 20/Apr/2020

Practical Explanation (contd)

  • The manual steps were
Ubuntu:
sudo apt-get update
sudo apt-get install apache2 -y
sudo systemctl enable apache2
sudo systemctl start apache2
sudo apt install php libapache2-mod-php php-mysql php-cli
sudo systemctl restart apache2
sudo vi /var/www/html/info.php
<?php phpinfo(); ?>
sudo systemctl restart apache2

Centos:
sudo yum install httpd -y
sudo systemctl enable httpd
sudo systemctl start httpd
sudo yum install php php-mysql php-fpm
sudo systemctl restart httpd
sudo vi /var/www/html/info.php
<?php 
phpinfo(); 
?>
sudo systemctl restart httpd

  • Pending steps to be automated
Ubuntu:
sudo vi /var/www/html/info.php
<?php phpinfo(); ?>
sudo systemctl restart apache2

Centos:
sudo vi /var/www/html/info.php
<?php phpinfo(); ?>
sudo systemctl restart httpd
  • To create a file we can
    • Create a file on workstation and upload to chef nodes
    • Download the file from some url into chef nodes
    • Create a file on the chef nodes
  • For the current cookbook i would create a file in cookbook and upload it.
    • Execute the following commands on terminal in workstation
chef generate
chef generate file --help
chef generate file . info.php
# a new folder files will be created in the cookbook

Preview Preview

  • Now navigate to install recipe and use the cookbook_file resource
#
# Cookbook:: .
# Recipe:: install
#
# Copyright:: 2020, The Authors, All Rights Reserved.

# using the attribute defined in the attributes/default.rb file

package_name = node['apache']['package_name']


package node['apache']['package_name'] do
    action :install
    notifies :enable, 'service[apache]'
end

service 'apache' do
    service_name node['apache']['package_name']
    action :nothing
end

packages = node['apache']['php_packages']

packages.each do |package_now|
    package package_now do
        action :install
        notifies :restart, 'service[apache]'
    end
end

cookbook_file '/var/www/html/info.php' do
    source 'info.php'
    action :create
    notifies :restart, 'service[apache]'
end

  • Now before uploading the cookbook to chef server, i want to review the cookbook i have written. chef has a tool called a foodcritic
cd <cookbook folder>
foodcritic .

Preview Preview

Practical Explanation Scenario with Tomcat Installation on Ubuntu

  • Refer Here
  • Try to use this on ubuntu 18 for installing tomcat-8
sudo apt-get update
sudo apt-get install tomcat8
sudo service tomcat8 restart
sudo apt-get install tomcat8-docs tomcat8-admin tomcat8-examples
sudo service tomcat8 restart

Is there a Need to write a cookbook from scratch all the time

  • Many user might have written lot of cookbooks, can i reuse them
  • Chef provides Chef-Supermarket, where there are cookbooks already written and ready to use, these are called as community cookbooks
  • Our tasks:
    • We need to learn how to use community cookbooks
    • We also need to learn how to write wrapper cookbooks Preview Preview

Leave a Reply

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

Please turn AdBlock off
Floating Social Media Icons by Acurax Wordpress Designers

Discover more from Direct DevOps from Quality Thought

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

Continue reading

Visit Us On FacebookVisit Us On LinkedinVisit Us On Youtube