Hello, everyone In this Article we are going to learn how we can install ansible in Linux in a very simple and easy step-by-step approach
I have created 3 machines as follow
1 For controller Machine and 2 For Worker Machine
- My Controller-Machine IP is – 54.86.70.84
- My Worker-1-Machine IP is – 52.201.192.62
- My Worker-2-Machine IP is – 23.20.53.232
My First machine is the controller machine and my second and third machine is the Worker-Machine
We need to check whether we can able to ping Machine second & Machine third with the Machine one with the IP address and the Hostname methods
Checking with the IP based method to check the connection With the machine-1 and machine-2
For Machine -1
For Machine-2
As we can see that we can able to ping to both Machine-2 and Machine-3 With the IP from our controller machine.
Now go to the Controller Node machine and edit the /etc/hosts file and we need to add the entry of both the Worker-1-Machine And Worker-2-Machine,
We are doing this step because we need to set up the hostname based communication between the Controller Machine and the Node Machine
Go to the Controller machine and edit the /etc/hosts file and add the IP of the Machine-2 and Machine-3 with their hostname
Testing the hostname connection between the Controller and the node-1 machine
Testing the hostname connection between the Controller and the node-2 machine
Now we have tested that we are now able to ping the controller machine with the Worker-1-Machine and Worker-2-Machine now we are ready to start our ansible lab
We called ansible as agentless this means that we don’t need to install any external agent to work with the ansible. As ansible works on SSH and by default the SSH service is installed in every Linux kernel soo we call the ansible agentless. But the fact is that we still need SSH to make the connection soo ansible is not agentless according to us
How we can install Ansible in Controller-Node
First check on controller Machine weather we have SSH package here.
# rpm -qa | grep openssh*
Now check on Worker-1-Machine that we have SSH Package here
Now check on Worker-2-Machine that we have SSH Package here
As we can see that we have SSH Package on all of 3 machine
We need to set the root password on Worker-1-Machine
We need to set the root password on Worker-2-Machine
We are setting the root password on Worker-1-Machine and Worker-2-Machine because when the controller node will execute the tasks on Worker-1-Machine and Worker-2-Machine then they must know the passwords for the root of both the machine
How to Make Login password less
We need to Make the Login to the Worker-1-Machine & Worker-2-Machine password less for the Controller Machine because we don’t want to specify the password every time when we run the ansible commands.
How to Generate key in Controller Machine
With the help of this command, we can generate the key on the controller machine that key will go to Worker Machine in order to make connection pass wordless
# ssh-key-gen
Now go to .ssh directory using cd command
# cd .ssh/
Now we need to run following command in order to Install key to our Worker-1-Machine. This will prompt the password for the Worker-1-Machine
# ssh-copy-id -i /root/.ssh/id_rsa.pub root@Worker-1-Machine
Now we need to run the following command in order to Install the key to our Worker-2-Machine. This will prompt the password for the Worker-2-Machine.
# ssh-copy-id -i /root/.ssh/id_rsa.pub root@Worker-2-Machine
Now we have make our Worker machine password less for controller machine
How to Install Ansible
First we need to Install EPEL script on our Controller machine this will give us extra packages
# yum install https://dl.fedoraproject.org/pub/epel/epel-release-latest-8.noarch.rpm
Sometimes we need to install python on the controller machine. With the help of # yum install python3 -y command we can install python in our Controller Machine. In my case, I don’t require to install python
Now execute the following command in order to install ansible in our controller Machine
# yum install ansible* -y
Just execute this command on the controller machine in order to install ansible on controller Mchine
To check weather ansible is installed or not execute # ansible —version command
Conclusion
If you want to learn Ansible in the most simple language then please click on this link
If you want to learn Linux in the most simple language then please click on this link.
This is the complete knowledge of how we can install ansible if you have any doubts please feel free to comment below. Please don’t forget to join our email subscription to get the latest updates on DevOps Articles