How to install Ansible on Ubuntu 18.04 Bionic Beaver Linux

Objective

The objective is to install Ansible on Ubuntu 18.04 Bionic Beaver Linux.

This guide will provide you with instructions on how to install Ansible on Ubuntu 18.04 from a standard Ubuntu repository, PPA repository and also how to install latest Ansible version by compiling the source code.

Operating System and Software Versions

  • Operating System: – Ubuntu 18.04 Bionic Beaver

Requirements

Privileged access to your Ubuntu System as root or via sudo command is required.

Difficulty

EASY – MEDIUM

Conventions

  • # – requires given linux commands to be executed with root privileges either directly as a root user or by use of sudo command
  • $ – requires given linux commands to be executed as a regular non-privileged user

Instructions

Install Ansible from Ubuntu Repository

The easiest way to install Ansible on Ubuntu system is by using the apt command and the standard Ubuntu package repository. Open up terminal and enter:

$ sudo apt install ansible

When successful, check your installed Ansible version:

$ ansible --version
ansible 2.3.1.0
  config file = /etc/ansible/ansible.cfg
  configured module search path = Default w/o overrides
  python version = 2.7.14+ (default, Feb  6 2018, 19:12:18) [GCC 7.3.0]


Install Ansible from PPA repository

This section will describe a procedure on how to install Ansible from the Ansible’s personal repository. Let’s start by importing Ansible signing keys:

$ sudo apt-key adv --keyserver keyserver.ubuntu.com --recv-keys 93C4A3FD7BB9C367
Executing: /tmp/apt-key-gpghome.qaCmAryJ6P/gpg.1.sh --keyserver keyserver.ubuntu.com --recv-keys 93C4A3FD7BB9C367
gpg: key 93C4A3FD7BB9C367: public key "Launchpad PPA for Ansible, Inc." imported
gpg: Total number processed: 1
gpg:               imported: 1

Next, add Ansible PPA repository:

$ sudo apt-add-repository "deb http://ppa.launchpad.net/ansible/ansible/ubuntu bionic main"

At this stage we are ready to install Ansible on our Ubuntu system:

$ sudo apt install ansible

Once installed, check your Ansible version:

$ ansible --version
ansible 2.6.1
  config file = /etc/ansible/ansible.cfg
  configured module search path = [u'/home/linuxconfig/.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.15rc1 (default, Apr 15 2018, 21:51:34) [GCC 7.3.0]

Install Ansible from Source

Here we will install Ansible on Ubuntu 18.04 system directly from the Ansible’s git repository. The advantage of this installation is that it will yield the highest Ansible version possible. Alternatively, we are able to choose the Ansible version to fit our environment.

To start with, we need to install required prerequisites. Execute the following linux command to perform the installation of all prerequisites:

$ sudo apt install make git make python-setuptools gcc python-dev libffi-dev libssl-dev python-packaging

Next, download Ansible source code using the git command:

$ git clone git://github.com/ansible/ansible.git

Navigate to the ansible directory:

$ cd ansible

This step is optional as it only allows you to select the desired Ansible version to be installed on your system. The following linux command will list all available Ansible versions:

$  git branch -a 


Alternatively, we can only list stable Ansible versions:

$  git branch -a | grep stable

Take a note of your desired version and execute git checkout. For example to set the Ansible version to stable-2.5 run:

$ git checkout stable-2.5

All what has left is to perform the compilation followed by the Ansible installation:

$ make
$ sudo make install

Once ready, confirm the Ansible installation by retrieving its version:

$ ansible --version
ansible 2.5.0rc2
  config file = None
  configured module search path = [u'/home/linuxconfig/.ansible/plugins/modules', u'/usr/share/ansible/plugins/modules']
  ansible python module location = /usr/local/lib/python2.7/dist-packages/ansible-2.5.0rc2-py2.7.egg/ansible
  executable location = /usr/local/bin/ansible
  python version = 2.7.14+ (default, Feb  6 2018, 19:12:18) [GCC 7.3.0]