How to Install and Configure Ansible on Ubuntu 18.04 [Quickstart]
How to Install and Configure Ansible on Ubuntu 18.04 [Quickstart]


How to Install and Configure Ansible on Ubuntu 18.04 [Quickstart]

UbuntuConfiguration ManagementAnsibleQuickstartUbuntu 18.04


In this guide, we will discuss how to install and configure Ansible on an Ubuntu 18.04 server. For a more detailed version of this tutorial, with more explanations of each step, please refer to How to Install and Configure Ansible on Ubuntu 18.04.


To follow this tutorial, you will need:

  • One Ansible Control Node: an Ubuntu 18.04 system where Ansible will be installed. This can be a remote server or a local machine.
  • One or more Ansible Hosts: one or more Ubuntu 18.04 servers that are accessible from your Control Node via SSH.

Step 1 — Install Ansible

From your control node, run the following command to include the official project’s PPA (personal package archive) in your system’s list of sources:

  • sudo apt-add-repository ppa:ansible/ansible

Refresh your system’s package index with:

  • sudo apt update

Following this update, you can install the Ansible software with:

  • sudo apt install ansible

Step 2 — Set Up the Inventory File

To edit the contents of your default Ansible inventory, open the /etc/ansible/hosts file using your text editor of choice:

  • sudo nano /etc/ansible/hosts

The default inventory file provided by the Ansible installation contains a number of examples that you can use as references for setting up your inventory. The following example defines a group named [servers] with three different servers in it, each identified by a custom alias: server1, server2, and server3. Be sure to replace the highlighted IPs with the IP addresses of your Ansible hosts.

server1 ansible_host=
server2 ansible_host=
server3 ansible_host=


The all:vars subgroup sets the ansible_python_interpreter host parameter that will be valid for all hosts in this inventory. This parameter makes sure the remote server uses the /usr/bin/python3 Python 3 executable instead of /usr/bin/python (Python 2.7), which is not present on recent Ubuntu versions.

Don’t forget to save and close the file when you’re finished.

Step 3 — Test Connection

You can use the -u argument to specify the remote system user. When not provided, Ansible will try to connect as your current system user on the control node.

From your Ansible control node, run:

  • ansible all -m ping -u root

You should get output similar to this:

server1 | SUCCESS => { "changed": false, "ping": "pong" } server2 | SUCCESS => { "changed": false, "ping": "pong" } server3 | SUCCESS => { "changed": false, "ping": "pong" }

If this is the first time you’re connecting to these servers via SSH, you’ll be asked to confirm the authenticity of the hosts you’re connecting to via Ansible. When prompted, type yes and then hit ENTER to confirm.

Once you get a "pong" reply back from a host, it means you’re ready to run Ansible commands and playbooks on that server.

Here are links to more detailed guides related to this tutorial:


Creative Commons License