Developer Advocate
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:
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
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.
[servers]
server1 ansible_host=203.0.113.111
server2 ansible_host=203.0.113.112
server3 ansible_host=203.0.113.113
[all:vars]
ansible_python_interpreter=/usr/bin/python3
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.
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:
Outputserver1 | 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.
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!