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

Published on April 16, 2020

Developer Advocate

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


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:

  1. sudo apt-add-repository ppa:ansible/ansible

Refresh your system’s package index with:

  1. sudo apt update

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

  1. 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:

  1. 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:

  1. 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:

Thanks for learning with the DigitalOcean Community. Check out our offerings for compute, storage, networking, and managed databases.

Learn more about our products

About the authors
Default avatar

Developer Advocate

Dev/Ops passionate about open source, PHP, and Linux.

Still looking for an answer?

Ask a questionSearch for more help

Was this helpful?
Leave a comment

This textbox defaults to using Markdown to format your answer.

You can type !ref in this text area to quickly search our full set of tutorials, documentation & marketplace offerings and insert the link!

Try DigitalOcean for free

Click below to sign up and get $200 of credit to try our products over 60 days!

Sign up

Join the Tech Talk
Success! Thank you! Please check your email for further details.

Please complete your information!

Featured on Community

Get our biweekly newsletter

Sign up for Infrastructure as a Newsletter.

Hollie's Hub for Good

Working on improving health and education, reducing inequality, and spurring economic growth? We'd like to help.

Become a contributor

Get paid to write technical tutorials and select a tech-focused charity to receive a matching donation.

Welcome to the developer cloud

DigitalOcean makes it simple to launch in the cloud and scale up as you grow — whether you're running one virtual machine or ten thousand.

Learn more
DigitalOcean Cloud Control Panel