March 10, 2023

How To Install Ansible On Ubuntu 20.04

Abhishek Thakur

Ansible is a software tool suite that enables infrastructure as code. It is open-source and includes software provisioning, configuration management, and application deployment functionality. Nobody enjoys doing the same thing over and over. IT administrators can use Ansible to start automating the drudgery out of their daily tasks. Automation frees up administrators’ time to focus on efforts that add more value to the business by shortening application delivery times and fostering a culture of success. Ansible assists in the management of multiple machines stored in a simple plain text files. The inventory is configurable, and target machine inventory can be sourced dynamically in various formats (YAML, INI) files. In this guide we will explain how to install and configure Ansible on Ubuntu 20.04.


Steps To Configure Ansible Control Node

First we will create a SSH keypair using which we will connect our host server. To do so enter the given command in your Ansible Control Node terminal.

# ssh-keygen

Generating SSH Keygen

The command will ask for a particular space where you want to save the file, you can skip to the default path by pressing enter. This will geretate the given output.


Finally the prompt will ask for a passphrase which will protect us from various security risk so please add a strong passphrase. Once the passphrase is set press enter and you will the given output.

SSH KEY generated


Steps To Configure Ansible Host Node

The Ansible control node monitors and controls Ansible hosts, which are remote servers. Each host must have the SSH key for the control node in the system user’s authorised keys directory. The easiest method to setup SSH key is to copy it using the given command. Replacing username(root) and remotehost(

# ssh-copy-id root@

The first time we will use this command it will ask for confirmation regarding connecting the new host. To continue type yes and press enter.

After that it searches for the public part of the key pair, once found the tool will ask for the host password. Enter the password and confirm it. Once it is done the public key will get added to the host system and it will generate the given output.

Configure SSH Key Ansible


Steps To Install Ansible On Ubuntu 20.04

Before proceeding further make sure the system is updated to the latest, to do so run the given commands.

# apt update

# apt upgrade

Once the system is updated we can finally start the installation by running the given command.

# apt install ansible

Next as the installation starts it will ask for confirmation type y and press enter to continue. Once installed we are ready to manage the remote hosts.


Configuring Ansible Inventory File For Managing Remote Hosts

Next we are going to setup a inventory file which will store the list of addresses of our remote hosts. By default the file is in /etc/ansible/hosts. Open the file with your favored editor by running the command.

# nano /etc/ansible/hosts

Browse to the bottom of the file and add new remote hosts. While adding new host keep the given format in check.

[category name] 
server_name ansible_host=[server_ip]

In this guide we added a remote host test1 and its IP address and sorted it in the test category.


Once changes are made write the file and save it. We can also check the list of remote host in inventory file by running the given command.

# ansible-inventory –list -y

Ansible Node


Verifying Ansible Remote Host Connections

In the final step we will make sure that the Ansible control node can connect to the remote host and run command. To test the connection to the remote host enter the given command in your Ansible Control Node terminal.

# ansible all -m ping

Ansible COntrol Node

This command uses Ansible’s built-in ping module to connect as root and run a connectivity test on all nodes from the default inventory file. The ping module tests:

  • If you have access to the host.
  • If you have valid SSH credentials.
  • If the host can run Ansible modules in Python.

Once you get a “pong” reply back from a host, it means you’re ready to run Ansible commands on your remote hosts.



In this guide, we installed Ansible, set up an inventory file, and used some test commands from the Ansible Control Node. You can now use Ansible to run commands on remote servers. 

Buy Dedicated Ansible Control Node @ $89/m Only

Popular Blog Posts