Ansible

What is Ansible?

Ansible is an open-source IT automation tool that automates configuration managementapplication deployment and many other manual IT processes.

 Unlike more simplistic management tools, Ansible users (like system administrators, developers and architects) can use Ansible automation to install software, automate daily tasks, provision infrastructure, improve security and compliance, patch systems, and share automation across the entire organization.





What is the need of Ansible? why companies use Ansible?


In big companies, there are thousands of servers that need to be configured daily. Now imagine if we have  to go and configure that each server manually by going to that particular pc or computer, how irritating  and time-consuming it would be And that is the reason why ansible was created. Ansible allows you to configure multiple apps and files at one time from one single computer/server using Infrastructure as code.


The server which has ansible installed is known as the Control node/server while the remote hosts/servers which are configured are known as Managed server

                                        

In ansible, you have two things to configure nd that are : -

  1. Ad-hoc commands (Command-line)
  2. Playbooks


Ad-hoc command ~ can be performed individually to perform a quick function.

Playbook ~ If we want to do anything in ansible we write a code in one file known as program file. The file that u create where u write the code is called program file is also known as playbook.

 The playbook contains three things: -

1) Name of the play.

2) Hosts

3)Tasks. 

The format used for writing playbooks is YAML.

Inventory~ File containing data about client server.

The remote servers or hosts which need to be configured are in the Inventory.

Things to do while using ansible.

  1. Creating Host server.
  2. Install Ansible to Host server.
  3. Creating 2 more EC2 instances (servers)
  4. Add these EC2s to inventory file.
  5. Configure the servers using command method.
  6. Uses of playbooks.
  7. Deployment of a simple webpage using Ansible.


Step-1

First of all we have to  create 3 EC2 instances. we have to  make sure that all three instance are created with same key pair. Our one server would be host server where we perform all the tasks and rest are other servers.

                              


STEP2

Now we will have to  install Ansible in host server (Ansible_host). You can follow the followings commands to install Ansible.

sudo apt update


sudo apt install ansible


STEP3
Copy the private key from local to Host server (Ansible_host) at (/home/ubuntu/.ssh). you can follow the following command to copy the key from local to Ansible_host.




STEP4
Now we will access the inventory file using 
~ cd .ssh
~vim ansible_key
~then copy paste the ansible key that was saved to downloads folder.                                                                                                                                                                                                            
Ansible ad hoc commands- using ad hoc commands is a quick way to run a single task on one or more managed nodes.
~ create a file using command mkdir
~ cd ansible
~vim hosts
~ansible-inventory --list -y








Now we will ping the servers and do some server configurations.




now, we have successfully ping the 2 hosts that we have defined in our host file and checked the disk space of both server at the same time just by a single command , that’s the power of Ansible. you can also perform some other tasks if you want.

STEP5

In this step we will learn about role of playbooks in ansible.


Playbooks are the simplest way in Ansible to automate repeating tasks in the form of resuable and consistent configuration files. Playbooks are defined in YAML files and any orderd set of steps to be executed in our managed nodes.

we will see some example of playbooks and execute them and see how can we configure the server.



Now we will run this playbook by using ( ansible-playbook <<name of play book>> ) .







so, as we can see in above screenshot that (create a file) is installed in both the server. so, it’s time to ssh one of the server and check whether (create a file) is installed or not.




As we can see we have successfully executed the playbook. we saw how powerful and effective this tool is.


STEP6

We  use a playbook to respond to an incident by creating an automation rule that will run when the incident is generated, and in turn it will call the playbook.






So, as you can see I have performed all the tasks successfully.

 THANK YOU

— Saurav Kumar




Comments