Set Up Ansible on Ubuntu 16.04

Table of Contents


Ansible is a configuration management system designed to make the process of configuring servers as quick and painless as possible. Although Ansible does not offer the power or flexibility of tools like Chef or Puppet, many system administrators simply don't need or want that level of complexity. Ansible is easy to use, easy to learn, and easy to deploy.


  • A 1&1 Cloud Server running Linux (Ubuntu 16.04)
  • A second 1&1 Cloud Server running Linux (any variety) to use for testing.

Install Ansible

Install the software-properties-common package:

sudo apt-get install software-properties-common

Add the official Ansible PPA:

sudo apt-add-repository ppa:ansible/ansible

Be sure to click Enter to continue when prompted.

Update the server:

sudo apt-get update

Install Ansible:

sudo apt-get install ansible

Edit the Ansible Hosts and Groups

Ansible uses the /etc/ansible/hosts file to check which servers it is responsible for contacting. Open this file for editing:

sudo nano /etc/ansible/hosts

The file has many examples (all of which are commented out with a # sign) which you can follow. The simplest form is:

[group name]
IP address or domain name of server 1
IP address or domain name of server 2 

For this test we will create one group named [pingtest] which will have the IP address of your second server for testing ( Add the following two lines to the top of the file:


Save and exit the file.

Create a directory for the Ansible groups:

sudo mkdir /etc/ansible/group_vars

Create a file for the pingtest group's variables and open it for editing:

sudo nano /etc/ansible/group_vars/pingtest

There are many variables you can put into these group files. For testing purposes, we will add only one: The username that Ansible will use to SSH to the testing server

To log in to the testing server as root, add the following two lines to this file:

ansible_ssh_user: root

If you log in with a different username, substitute it instead.

Save and exit the file.

Create and Deploy SSH Keys

The main Ansible server will need to be able to SSH to its host servers without having to log in with a username and password. To do this, we will set up SSH keys.

On the main Ansible server, generate the SSH keys:

sudo ssh-keygen -t rsa

Then copy the public key file to the testing server

sudo ssh-copy-id -i ~/.ssh/ root@

To verify that the SSH keys are set up correctly, SSH to the testing server from the main Ansible server:

ssh root@

You will be logged in to the remote server without having to enter a username and password.

Test the Ansible Deployment

Use ansible -m ping all to ping all of the hosts, to verify that Ansible is set up correctly. The server will respond with:

root@localhost:~# ansible -m ping all | SUCCESS => {
    "changed": false,
    "ping": "pong"

Content provided by 1&1


Tags: Ansible