Create a cookbook to install tree and elinks on ubuntu nodes
- Create a cookbook
- Naviagate to default.rb in recipes
- 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
- Find a resource for apt-get update and google
apt-update in chefand results point to here
- 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'
- Now sudo apt-get install tree and resource syntax looks as shown below
- 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
- 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
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
- 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.