How to Install Ansible on Ubuntu 20.04 LTS

In this article we are going to cover How to install Ansible on Ubuntu 20.04 LTS, Configure Ansible, exchanged SSH keys from master to slave node and Tested the Ansible setup.

Prerequisites:

  • Minimum 3 instance of Ubuntu 1 for Ansible server and another 2 for Nodes
  • SSH access with sudo privileges
  • A good internet connection

#1.Adding Ansible Repository in Ubuntu

Now we are going yo run below commands on Ansible server 

Step1 :Update your system packages:

     sudo apt-get update

Step2: First Install Required packages to install Ansible.

sudo apt install software-properties-common

Step3: Add the ansible repository via PPA

sudo add-apt-repository --yes --update ppa:ansible/ansible

#2.Install Ansible on Ubuntu 20.04 LTS

Step1: Install Ansible on Ubuntu 20.04 LTS

     sudo apt-get install ansible

Step2: To check version :

     ansible --version

#3.Create Inventory file in Ansible

To add inventory you can create new directory or add in default ansible hosts file

step1:Now go to host file inside ansible server and paste private ip of node1 and node2:

sudo nano /etc/ansible/hosts

You can create group and paste ip address like below:

[devopshint]
65.2.140.xx
65.3.144.xx

#4.Configuration of Ansible server

Step1: This host file is only working after updating ansible.cfg file inside ansible server:

sudo nano /etc/ansible/ansible.cfg 

    Uncomment below lines 

  inventory = /etc/ansible/hosts
  sudo-user = root

Step2: Now, create one user in all these instance(ansible server and nodes)

sudo adduser ansible
sudo passwd ansible

now navigate the ansible user 

su - ansible 

try to create a some file and install some package

you got some error like this 

This ansible user doesn’t have sudo privileges right now

If you want to give sudo privileges to ansible user then run below command

#5.Add User to the sudo Group

Step1: Give some privileged in all nodes(ansible server and node) using below command:

  sudo visudo 

go to inside this file and add this line

ansible ALL=(ALL) NOPASSWD:ALL

#6.Update ssh_config file

For SSH connection to node from Ansible server make changes in sshd_config file

Step1: Now we have to some changes in ssh-config file in ansible server and nodes:

sudo nano /etc/ssh/sshd_config

Then you need to uncomment these two lines

PubkeyAuthentication yes
PasswordAuthentication yes

Now we need to restart sshd service:

sudo systemctl restart sshd

Lets check the status:

sudo systemctl status sshd

#7.Ansible Master and Slave Setup

 Go to ansible server run the below command

Step1: login to ansible in ansible server using below command:

su - ansible

Step2: Run the below command to connect node:

ssh ip_address ( node ip)

#8.Setup SSH keys and share it among managed nodes

To communicate with client we have to genrate SSH key on ansible server node and exchange with Slave/Client Systems.

Step1: we need to generate ssh keygen in ansible server

ssh-keygen 

Step2: you need to inside .ssh:

cd .ssh

Step3:Now run the below command using private ip of your node:

ssh-copy-id ansible@{private address } 

Conclusion:

In this article we have covered How to install Ansible on Ubuntu 20.04 LTS, Configure ansible, exchanged SSH keys from master to slave node and Tested the ansible setup.

Related Articles:

How to Install Ansible on Ubuntu 18.04/16.04 LTS

Reference:

Ansible Installation official page

Shweta Mamidwar

I am Shweta Mamidwar working as a Intern in Product Company. Likes to share knowledge.

1 thought on “How to Install Ansible on Ubuntu 20.04 LTS”

Leave a Comment

This site uses Akismet to reduce spam. Learn how your comment data is processed.

Share via
Copy link
Powered by Social Snap