How to Install Ansible on Ubuntu 18.04

27 June 2020 | Category : Ubuntu

How to Install Ansible on Ubuntu 18.04

What is Ansible?

Ansible is an open-source automation engine tool for cloud provision, application deployment, configuration management. Ansible can help Linux System Administrator or DevOps to manage several Servers, including improving scalability.

Right now, the automation tool is very crucial, why that is very crucial? because these days a Linux System Administrator or DevOps can handle dozens of servers. This is a reason the automation tool is crucial and needed for managing configuration server or improving scalability.

Ansible is written in Python, so to install Ansible in your local environment you need Python version 2.7 or version 3.5 installed.

How does Ansible work?

Ansible uses SSH connection as channel communication between the control node(your local environment) to managed nodes, from SSH connection Ansible will send/retrieve information where the command which sent from the local environment to servers. So, Ansible doesn’t use agents and it’s easy to use deployment.
In this article, we will show to you How To Install Ansible on Ubuntu 18.04 in two ways from pip command and installing from package command.

Install Ansible on Ubuntu 18.04

Such as discussed earlier, we will show you how to install ansible on ubuntu 18.04 in two ways. You can choose one from these two ways to install ansible in your local environment.

Option 1: Install with PIP command

To install Ansible with pip command, make sure in your local environment has been installed Python version 2.7 or 3.5. If Python has been installed you can follow this command to installing ansible.

Before you install ansible you need pip command installed on your local environment. So, If you use Python version 2.7 you can install PIP with this command:

sudo apt install -y python-pip

Or if you use Python version 3.5 you can follow this command :

sudo apt install -y python3-pip

Next, if pip command already installed you can install Ansible with this command in your local environment :

sudo pip install ansible

Option 2: Install with package command

To install from package command, you can run this command :

sudo apt install -y ansible

This command will automatically download the package of ansible from repository Ubuntu 18.04.

Verify Ansible Installation

After finished install ansible from pip command or package command, you can verify that installation with this command :

ansible --version

That command will show the output like this :

ansible --version
ansible 2.9.10
config file = /etc/ansible/ansible.cfg
configured module search path = [u'/root/.ansible/plugins/modules',u'/usr/share/ansible/plugins/modules']
ansible python module location = /usr/local/lib/python2.7/dist-packages/ansible
executable location = /usr/local/bin/ansible
python version = 2.7.17 (default, Apr 15 2020, 17:20:14) [GCC 7.5.0]  

When the installation successful the output will show the message similar above

Getting Started

Now, your Ansible is already installed, and let’s try to make simple provision to manage your private Server. To make simple provision you should create some configuration file in yaml format, Ansible uses yaml as default format configuration. This is the step of creating a simple provision configuration with Ansible :

1. Create Inventory

The first step to creating a simple provision configuration you must define inventory. What is inventory? Inventory is a configuration file where is in this folder/file containing an IP of the server by default a location of the inventory file called at /etc/ansible/hosts. So, if you want to define your inventory in different/folder you can follow this step :

    mkdir -p ansible/inventory && cd ansible/inventory

After that, you can create file hosts for the inventory of your IP Server and add your IP Server into hosts file.

    touch hosts && vim hosts

For example format of hosts file you can contain like below :


2. Connect to Managed Nodes

And then after create custom file hosts location and to make sure if ansible has been connected to managed nodes you need test connection to your Server, to do that you can follow this step.
Generate your SSH Key with the command :

    ssh-keygen -t rsa

Then, copy your SSH Key into your server with command :

    ssh-copy-id root@hostnameserver -p 22

Next, if SSH Key successfully copied into your server. You can try this command of ansible to test check connection with ping.

    ansible -i inventory/hosts all -u root -m ping

And the output result of that command will show below :

 ansible -i inventory/hosts all -u root -m ping | SUCCESS => {
   "ansible_facts": {
      "discovered_interpreter_python": "/usr/bin/python"
    "changed": false,
    "ping": "pong"

With the result of ping showing SUCCESS, that means your local environment now has been connected to managed nodes.


Ansible makes Linux System Administrator and DevOps easy to manage dozens of Servers. With this tool, you don’t need to be logged into the server one by one to manage or modify some configuration. You just create some file configuration with called ansible-playbook and run that file configuration to implement your configuration into several servers. In the next time, we will post about how to create ansible-playbook to manage or configure the server. We hope this article How to Install Ansible on Ubuntu 18.04 can help you to install Ansible in your local environment.

Share this article :