How to Install and Use Ansible on Ubuntu 16.04


  • Two Alibaba Cloud ECS instance with Ubuntu 16.04 installed.
  • A static IP address is configured on server node.
  • A static IP address is configured on client node.
  • Root password is configured on each node.

Launch Alibaba Cloud ECS instance

First, Login to your">Alibaba Cloud ECS Console. You will be redirected to the main dashboard. You will need to navigate to your ECS instance by selecting the appropriate region. For this tutorial, I have created my ECS instances in the Singapore region.

Install Ansible

By default, Ansible is not available in Ubuntu 16.04 repository. So you will need to add Ansible personal repository to on the server node. You can add the repository using the following command:

Ansible is a radically simple IT automation platform that makes your applications and systems easier to deploy. Avoid writing scripts or custom code to deploy and update your applications— automate in a language that approaches plain English, using SSH, with no agents to install on remote systems.
More info:
Press [ENTER] to continue or ctrl-c to cancel adding it
gpg: keyring `/tmp/tmpiylu9n1t/secring.gpg' created
gpg: keyring `/tmp/tmpiylu9n1t/pubring.gpg' created
gpg: requesting key 7BB9C367 from hkp server
gpg: /tmp/tmpiylu9n1t/trustdb.gpg: trustdb created
gpg: key 7BB9C367: public key "Launchpad PPA for Ansible, Inc." imported
gpg: Total number processed: 1
gpg: imported: 1 (RSA: 1)

Configure Ansible Host

Ansible keeps track of all of the server nodes and client nodes using a hosts file. So you will need to configure this file before communicate with our other nodes.

client-node ansible_ssh_host=

Setup SSH Keys for Remote Hosts

Ansible uses SSH to communicate with other nodes. So you will need to generate an SSH key on server node and copy the ssh keys to the client node.

Generating public/private rsa key pair.
Enter file in which to save the key (/root/.ssh/id_rsa):
Enter passphrase (empty for no passphrase):
Enter same passphrase again:
Your identification has been saved in /root/.ssh/id_rsa.
Your public key has been saved in /root/.ssh/
The key fingerprint is:
SHA256:3FvzXmI3EhW7idSZy+ITzW7UrefZP/R5AYx2VBu3ytU root@server-node
The key's randomart image is:
+---[RSA 4096]----+
| .+.|
| .. @|
| +. XE|
| . . oo+O *|
| S o +B.Oo|
| o.o*+ |
| . +*+B|
| o+O*|
| ..B|

Test Ansible

Once everything is configured properly, it’s time to test Ansible.

client-node | SUCCESS => {
"changed": false,
"failed": false,
"ping": "pong"
ansible -m ping client-node
ansible -m ping servers
client-node | SUCCESS | rc=0 >>
total used free shared buffers cached
Mem: 3835 3185 649 177 77 929
-/+ buffers/cache: 2179 1656
Swap: 10793 0 10793
client-node | SUCCESS | rc=0 >>
Filesystem Size Used Avail Use% Mounted on
/dev/sda4 92G 27G 61G 31% /
none 4.0K 0 4.0K 0% /sys/fs/cgroup
udev 1.9G 4.0K 1.9G 1% /dev
tmpfs 384M 1.2M 383M 1% /run
none 5.0M 0 5.0M 0% /run/lock
none 1.9G 1.9M 1.9G 1% /run/shm
none 100M 44K 100M 1% /run/user
/dev/sda5 353G 75G 261G 23% /Data


Congratulations! You have successfully configured Ansible on your Alibaba Cloud ECS server. You can now easily manage multiple server by executing single command from central location.



Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store
Alibaba Cloud

Alibaba Cloud

Follow me to keep abreast with the latest technology news, industry insights, and developer trends. Alibaba Cloud website: