Step by Step Guide on How to Install Ansible on Ubuntu

Getting your Trinity Audio player ready...

In this article, I am going to share how to install ansible on ubuntu. If you already have an idea about ansible then it is OK.

You can understand Ansible is one of the best open-source automation tools as compared to many other automation tools like Chef & Puppet. Ansible is managed by Redhat.

How to Install Ansible on Ubuntu

This will be 5 step procedure for how to install ansible on ubuntu along with some validation stuff and man command for ansible to get started with ansible.

Step 1. $ sudo apt-get update
Step 2. $ sudo apt-get install software-properties-common
Step 3. $ sudo apt-add-repository ppa:ansible/ansible
Step 4. $ sudo apt-add-repository ppa:ansible/ansible
Step 5. $ sudo apt-get install ansible

Validation steps and tips to gets started.

Step6. $ sudo ansible --version
Step7 .$ sudo ansible -help

So before just getting started let me share about the environment where this installation procedure has been tested to show step by step procedure.

It is expected to work everywhere unless any specific error in your OS setup.

# uname -a
Linux host01 4.4.0-193-generic #224-Ubuntu SMP Tue Oct 6 GNU/Linux

So let us see it step by step procedure with sample output.

[maxbutton id=”15″ ]

Step 1. $ sudo apt-get update

# sudo apt-get update
Hit:1 xenial InRelease
Get:2 xenial-security InRelease [109 kB]
Get:3 xenial InRelease [18.1 kB]
Get:4 xenial-updates InRelease [109 kB]
Get:5 xenial-backports InRelease [107 kB]
Hit:6 stable InRelease
Get:7 bionic InRelease [64.4 kB]
Get:8 xenial/main amd64 Packages [35.0 kB]
Get:9 xenial-security/main amd64 Packages [1,504 kB]
Get:10 xenial/main i386 Packages [34.9 kB]
Get:11 xenial InRelease [4,584 B]
Get:12 xenial-updates/main amd64 Packages [1,907 kB]
Get:13 xenial-updates/main i386 Packages [1,459 kB]
Get:14 xenial-updates/main Translation-en [459 kB]
Get:15 xenial-updates/universe amd64 Packages [1,208 kB]
Get:16 xenial-updates/universe i386 Packages [1,076 kB]
Get:17 xenial-updates/universe Translation-en [352 kB]
Get:18 xenial-updates/multiverse amd64 Packages [23.0 kB]
Get:19 xenial-updates/multiverse i386 Packages [21.8 kB]
Get:20 xenial-security/main i386 Packages [1,092 kB]
Get:21 bionic/stable amd64 Packages [14.9 kB]
Get:22 xenial-security/main Translation-en [356 kB]
Get:23 xenial/main amd64 Packages [763 B]
Get:24 xenial-security/universe amd64 Packages [781 kB]
Get:25 xenial-security/universe i386 Packages [660 kB]
Get:26 xenial-security/universe Translation-en [222 kB]
Get:27 xenial-security/multiverse amd64 Packages [8,232 B]
Get:28 xenial-security/multiverse i386 Packages [8,480 B]
Fetched 11.6 MB in 21s (530 kB/s)
Reading package lists... Done

Step 2. $ sudo apt-get install software-properties-common

# sudo apt-get install software-properties-common
Reading package lists... Done
Building dependency tree
Reading state information... Done
software-properties-common is already the newest version (
The following package was automatically installed and is no longer required:
Use 'sudo apt autoremove' to remove it.
0 to upgrade, 0 to newly install, 0 to remove and 39 not to upgrade.

Step 3. $ sudo apt-add-repository ppa:ansible/ansible

# sudo apt-add-repository ppa:ansible/ansible
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/tmp6f0n1c0g/secring.gpg' created
gpg: keyring `/tmp/tmp6f0n1c0g/pubring.gpg' created
gpg: requesting key 7BB9C367 from hkp server
gpg: /tmp/tmp6f0n1c0g/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)

Step 4. $ sudo apt-get update

# sudo apt-get update
Get:1 xenial InRelease [18.0 kB]
Hit:2 xenial InRelease
Hit:3 xenial-updates InRelease
Hit:4 xenial-backports InRelease
Hit:5 xenial InRelease
Hit:6 stable InRelease
Hit:7 xenial-security InRelease
Hit:8 bionic InRelease
Hit:9 xenial InRelease
Get:10 xenial/main amd64 Packages [696 B]
Get:11 xenial/main i386 Packages [696 B]
Get:12 xenial/main Translation-en [472 B]
Fetched 19.9 kB in 1s (19.4 kB/s)
Reading package lists... Done

[maxbutton id=”11″ ]

Step 5. $ sudo apt-get install ansible

# sudo apt-get install ansible
Reading package lists... Done
Building dependency tree
Reading state information... Done
The following packages were automatically installed and are no longer required:
ieee-data libuv1 python-netaddr python-selinux
Use 'sudo apt autoremove' to remove them.
The following additional packages will be installed:
python-cffi-backend python-cryptography python-enum34 python-idna python-ipaddress
Suggested packages:
python-cryptography-doc python-cryptography-vectors python-enum34-doc doc-base
The following NEW packages will be installed
python-cffi-backend python-cryptography python-enum34 python-idna python-ipaddress
The following packages will be upgraded:
1 to upgrade, 6 to newly install, 0 to remove and 39 not to upgrade.
Need to get 6,184 kB of archives.
After this operation, 53.3 MB of additional disk space will be used.
Do you want to continue? [Y/n] Y
Get:1 xenial/main amd64 ansible all 2.9.16-1ppa~xenial[5,792 kB]
Get:2 xenial/main amd64python-cffi-backend amd64 1.5.2-1ubuntu1[58.1 kB]
Get:3 xenial/main amd64 python-enum34 all 1.1.2-1 [35.8 kB]
Get:4 xenial/main amd64 python-idna all 2.0-3 [35.1 kB]
Get:5 xenial/main amd64 python-ipaddress all 1.0.16-1 [18.0 kB]
Get:6 xenial/main amd64 python-pyasn1 all 0.1.9-1 [45.1 kB]
Get:7 xenial-updates/main amd64 python-cryptography amd64 1.2.3-
1ubuntu0.3 [200 kB]
Fetched 6,184 kB in 0s (24.5 MB/s)
debconf: Unable to initialise frontend: Dialog
debconf: (Dialogue frontend requires a screen at least 13 lines tall and 31 columns wide.)
debconf: falling back to frontend: Readline
Selecting previously unselected package python-cffi-backend.
(Reading database ... 115521 files and directories currently installed.)
Preparing to unpack .../python-cffi-backend_1.5.2-1ubuntu1_amd64.deb ...
Unpacking python-cffi-backend (1.5.2-1ubuntu1) ...
Selecting previously unselected package python-enum34.
Preparing to unpack .../python-enum34_1.1.2-1_all.deb ...
Unpacking python-enum34 (1.1.2-1) ...
Selecting previously unselected package python-idna.
Preparing to unpack .../python-idna_2.0-3_all.deb ...
Unpacking python-idna (2.0-3) ...
Selecting previously unselected package python-ipaddress.
Preparing to unpack .../python-ipaddress_1.0.16-1_all.deb ...
Unpacking python-ipaddress (1.0.16-1) ...
Selecting previously unselected package python-pyasn1.
Preparing to unpack .../python-pyasn1_0.1.9-1_all.deb ...
Unpacking python-pyasn1 (0.1.9-1) ...
Selecting previously unselected package python-cryptography.
Preparing to unpack .../python-cryptography_1.2.3-1ubuntu0.3_amd64.deb ...
Unpacking python-cryptography (1.2.3-1ubuntu0.3) ...
Preparing to unpack .../ansible_2.9.16-1ppa~xenial_all.deb ...
Unpacking ansible (2.9.16-1ppa~xenial) over ( ...
Processing triggers for man-db (2.7.5-1) ...
Setting up python-cffi-backend (1.5.2-1ubuntu1) ...
Setting up python-enum34 (1.1.2-1) ...
Setting up python-idna (2.0-3) ...
Setting up python-ipaddress (1.0.16-1) ...
Setting up python-pyasn1 (0.1.9-1) ...
Setting up python-cryptography (1.2.3-1ubuntu0.3) ...
Setting up ansible (2.9.16-1ppa~xenial) ...
Installing new version of config file /etc/ansible/ansible.cfg ...
Installing new version of config file /etc/ansible/hosts ...

That`s all about how to install ansible on ubuntu. You can review python dependency also gets installed.

You are all set. You can validate functionality as mentioned earlier as step 6 and step 7 and you can start exploring the journey of automation

Step6. $ sudo ansible –version

# ansible --version 
ansible 2.9.16 
config file = /etc/ansible/ansible.cfg 
configured module search path = [u'/root/.ansible/plugins/modules', u'/usr/share/ansible/plugins/modules']
ansible python module location = /usr/lib/python2.7/dist-packages/
ansible executable location = /usr/bin/ansible python version = 2.7.12 
(default, Oct 5 2020, 13:56:01) [GCC 5.4.0 20160609]

[maxbutton id=”1″ ]

Step7 .$ sudo ansible -help

Start exploring after having a good look at options available with ansible.

# ansible -help
usage: ansible [-h] [--version] [-v] [-b] [--become-method BECOME_METHOD]
[--become-user BECOME_USER] [-K] [-i INVENTORY] [--list-hosts] [-l SUBSET] 
[-P POLL_INTERVAL] [-B SECONDS] [-o] [-t TREE] [-k] [--private-key PRIVATE_KEY_FILE] [-u REMOTE_USER]
[-c CONNECTION] [-T TIMEOUT][--ssh-common-args SSH_COMMON_ARGS]
[--sftp-extra-args SFTP_EXTRA_ARGS][--scp-extra-args SCP_EXTRA_ARGS] [--ssh-extra-args SSH_EXTRA_ARGS] [-C] 
[--syntax-check] [-D] [-e EXTRA_VARS] [--vault-id VAULT_IDS] [-a MODULE_ARGS] [-m MODULE_NAME]
[--ask-vault-pass | --vault-password-file VAULT_PASSWORD_FILES] [-f FORKS] [-M MODULE_PATH] [--playbook-dir BASEDIR]
Define and run a single task 'playbook' against a set of hosts positional arguments:pattern host pattern.optional arguments:
--ask-vault-pass ask for vault password --list-hosts outputs a list of matching hosts; does not execute anything else.
--playbook-dir BASEDIR Since this tool does not use playbooks, use this as a substitute playbook directory.This sets the relative 
path for many features including roles/group_vars/ etc.
--syntax-check perform a syntax check on the playbook, but do not execute it
--vault-id VAULT_IDS the vault identity to use
--vault-password-file VAULT_PASSWORD_FILES vault password file
--version show program's version number, config file location,configured module search path, module
location,executable location and exit.
-B SECONDS, --background SECONDS run asynchronously, failing after X seconds (default=N/A)
-C, --check don't make any changes; instead, try to predict some of the changes that may occur
-D, --diff when changing (small) files and templates, show the differences in those files; works 
great with --check
-M MODULE_PATH, --module-path MODULE_PATH prepend colon-separated path(s) to module 
library (def ault=~/.ansible/plugins/modules:/usr/share/ansible/plugins/modules)
-P POLL_INTERVAL, --poll POLL_INTERVAL set the poll interval if using -B (default=15) -a 
MODULE_ARGS, --args MODULE_ARGS module arguments -e EXTRA_VARS, --extra-vars 
EXTRA_VARS set additional variables as key=value or YAML/JSON, if filename prepend with @
-f FORKS, --forks FORKS specify number of parallel processes to use (default=5)
-h, --help show this help message and exit
-i INVENTORY, --inventory INVENTORY, --inventory-file INVENTORY specify inventory host path or comma separated host 
list. --inventory-file is deprecated.
-l SUBSET, --limit SUBSET further limit selected hosts to an additional pattern 
-m MODULE_NAME, --module-name MODULE_NAME module name to execute (default=command)
-o, --one-line condense output
-t TREE, --tree TREE log output to this directory
-v, --verbose verbose mode (-vvv for more, -vvvv to enable connection debugging)
Privilege Escalation Options:
control how and which user you become as on target hosts --become-method BECOME_METHOD
privilege escalation method to use (default=sudo), use `ansible-doc -t become -l` to list valid 
--become-user BECOME_USER run operations as this user (default=root)  -K, --ask-become-pass
ask for privilege escalation password -b, --become run operations with become (does not imply 
password prompting).
Connection Options:control as whom and how to connect to hosts.
--private-key PRIVATE_KEY_FILE, --key-file PRIVATE_KEY_FILE use this file to authenticate the
--scp-extra-args SCP_EXTRA_ARGS specify extra arguments to pass to scp only (e.g. -l)
--sftp-extra-args SFTP_EXTRA_ARGS specify extra arguments to pass to sftp only (e.g. -f,-l)
--ssh-common-args SSH_COMMON_ARGS specify common arguments to pass to sftp/scp/ssh (e.g.
--ssh-extra-args SSH_EXTRA_ARGS specify extra arguments to pass to ssh only (e.g. -R)
-T TIMEOUT, --timeout TIMEOUT override the connection timeout in seconds (default=10)
-c CONNECTION, --connection CONNECTION connection type to use (default=smart) -k, --ask-pas
s ask for connection password
-u REMOTE_USER, --user REMOTE_USER connect as this user (default=None)
Some modules do not make sense in Ad-Hoc (include, meta, etc)
root@host01 :

Thanks for going through it. I hope it will help by some means especially those who are just starting with Ansible.

Request you to share and subscribe and allow the post will go to the right set of people which will help the post objectively.

You can check the below articles if you want to explore more any related subject…