DevOps classroom Series – 13/Apr/2020

Create a cookbook to install tree and elinks on ubuntu nodes

  1. Create a cookbook
  2. Naviagate to default.rb in recipes
  3. Manual commands to install tree and elinks on ubuntu are
sudo apt-get update
sudo apt-get install tree -y
sudo apt-get install elinks -y
  1. Find a resource for apt-get update and google apt-update in chef and results point to here
  2. default.rb is default recipe and updating that would look like
#
# Cookbook:: myutilities
# Recipe:: default
#
# Copyright:: 2020, The Authors, All Rights Reserved.

# Manual command to install tree on ubuntu is 
# sudo apt-get update 
# sudo apt-get install tree

apt_update 'update'
  1. Now sudo apt-get install tree and resource syntax looks as shown below Preview Preview Preview
  2. Modified cookbook to install elinks, tree and git
#
# Cookbook:: myutilities
# Recipe:: default
#
# Copyright:: 2020, The Authors, All Rights Reserved.

# Manual command to install tree on ubuntu is 
# sudo apt-get update 
# sudo apt-get install tree
# sudo apt-get install elinks
# sudo apt-get install git

apt_update 'update'

apt_package 'mytree' do
    package_name  'tree'
    action :install
end

apt_package 'myelinks' do
    package_name  'elinks'
    action :install
end

apt_package 'mygit' do
    package_name 'git'
    action :install
end

  • Lets upload this cookbook to chef infra server
cd <chef-repo>\cookbooks\<cookbook-name>
berks install
berks upload
  • To verify the upload of the cookbook
knife cookbook list

Preview

  • Now lets edit run list from manage.chef.io to ubuntu nodes and verify the installation of git, tree and elinks
  • Wait for the convergance to happen or in this case i had manually forced convergance Preview

Chef Learning Approach

  • Writing Chef Cookbooks (Learning Chef Domain Specific Language)
    • Its not a good idea to have un tested cookbooks uploaded to chef server.
  • Manage the Chef infrastructure

Test-Kitchen

  • To learn writing chef cookbooks and testing them, we will be using test-kitchen from chef
  • Test-Kitchen helps in doing development, testing of the cookbooks from workstation without need of chef-server and chef-nodes and this is going to be your chef development setup.

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