Bootstrapping one more node
- This time lets create a ubuntu node from azure Refer Here for creating a vm in azure

- Now lets bootstrap this node by using knife command
knife bootstrap 52.152.147.178 -U qtdevops -P motherindia@123 --sudo -N azurenode

- Lets look at node list from command line and ui

Lets create a simple workflow to install git on all of our nodes
- Working Principles:
- Before we try to automate any thing in chef, first get to know the manual way of doing it.
- Make a list of the commands you need to execute for your application deployment
- How to work the above in chef:
- In chef to automate the deployment we create cookbooks
- In this case let me call this as utility cookbook
- Navigate to your chef-repo/cookbooks folder in the terminal
- To generate a cookbooks, when we install chefdk, we get a command line tool called as chef. This tool chef has a sub command called as generate
chef generate --help chef generate cookbook --help
- From the above documentation our command will be
chef generate cookbook utility
- When we generated the cookbook we got some files and folders as shown below

- In chef to automate the deployment we create cookbooks
- Cookbook: cookbook defines a scenario (application deployment) and contains everything that is required to automate the scenario
- We have already understood that cookbook is collection of recipes & many other things, but lets focus on recipes
- In the generated cookbook there is already a folder called as recipes and there is file called as default.rb

- In chef, we write all of recipes inside the recipes folder & the default recipe is default.rb file.
- So recipe will be a .rb file inside recipes folder in a cookbook.
- Chef uses ruby and .rb stands for ruby file. Inside recipes you can use a custom language (DSL) developed by chef or plain ruby.
- We understood that recipe is resources written in a specific order.
- How to write a resource & what is resource
- Resource is smallest unit of automation in chef where you can describe the desired state
- The resource syntax in chef is
<resource_type> 'resource name' do <property-1> <value-1> .. action <action to be performed> end- Example of chef resource
service 'apache2' do action :restart end - The manual commands to install git on ubuntu
sudo apt-get update
sudo apt-get install git -y
- For every manual command try to find a chef resource.
- The easiest way to find a resource is google the pattern of search is apt-get update in chef

- Open the documentation and look at the highlighted sections

- The resource code in the recipes/default.rb
apt_update 'update ubuntu packages' do action :update end- Now lets find a resource for apt-get install git

- Now the recipes/default.rb will be as shown below
# # Cookbook:: utility # Recipe:: default # # Copyright:: 2020, The Authors, All Rights Reserved. apt_update 'update ubuntu packages' do action :update end apt_package 'git' do action :install end - The easiest way to find a resource is google the pattern of search is apt-get update in chef
- Now we need to upload cookbook to chef server. The steps for doing that is Refer here
knife cookbook upload --help
knife cookbook upload utility

- Now verify the cookbook in manage.chef.io

- Since the cookbook is uploaded, we need to inform chef server on which nodes this recipe should be executed. Chef does this by a concept called run_list. Consider run_list to be a list of recipes to be executed on the node. In chef every node will have one run_list.
- Select the node on the Server UI and edit the run_list

- Now chef server will execute this cookbook during next convergence. For this session, lets manually force converge. Login into the node and execute
sudo chef-client

