left-icon

Ansible Succinctly®
by Zoran Maksimovic

Previous
Chapter

of
A
A
A

CHAPTER 4

Installing Ansible

Installing Ansible


We will be installing the Ansible software on our Ansible Manager server amgr, which we started up previously. From there, we will be orchestrating the execution of the code. There are two main ways to install and use Ansible on the host:

  • Using the operating system package manager (apt-get, yum), depending on the operating system in use.
  • Install Ansible by using pip, which is the Python package manager.

Ansible creates new releases a couple of times per year. Due to this short release cycle, minor bugs will generally be fixed in the next release. Major bugs will still have maintenance releases when needed, though these are not so frequent.

Note: Although you can try both installation options, in this book we will be using the installation through pip.

Using the OS package manager

Installing Ansible by using the OS package manager obviously depends on the operating system (and distribution, in case of Linux). As mentioned previously, we are using CentOS.

Installing Ansible on CentOS

Throughout this book, we are using CentOS as our example Linux distribution. CentOS is a good choice, as it is secure, has a good package-management software, and is well documented. The chance of finding it in an enterprise environment is quite high.

Let’s log into the amgr server by running the following command.

Code Listing 15: Log into the amgr host

PS C:\>AnsibleSuccinctly\Vagrant>vagrant ssh amgr

Or alternatively (when asked, provide vagrant as password)

PS C:\>ssh [email protected]

Once logged into the amgr host, we’ll use the Ansible installation command.

Code Listing 16: Installing Ansible command

[vagrant@amgr ~]$ sudo yum install ansible

To check that Ansible has been properly installed, let’s run the following command.

Code Listing 17: Checking the Ansible version

[vagrant@amgr ~]$ ansible --version

The result returned should be similar to what is shown in Figure 13. You can see that the result returned shows a lot of information about the installed software, such as the version (in our case Ansible 2.9.18) and the configuration settings, such as configuration file location and Ansible location.

Ansible version information

Figure 13: Ansible version information

Installing Ansible by using pip

The standard package manager for Python is pip. It allows you to install and manage additional packages that are not part of the Python standard library.

If pip is not already installed (as in our case currently), we should install it first.

Note: If you have followed the previous installation by using the package manager, you can simply destroy the amgr machine and create a new one to have a clean environment [vagrant destroy amgr, vagrant up amgr].

As we did previously, we should login to the amgr host first.

PS C:\>AnsibleSuccinctly\Vagrant> vagrant ssh amgr

Note: Throughout this book, we will be using Ansible installed by using pip and within a virtual environment.

Installing Python and pip

To install pip, we need to install the Python framework, which already contains the pip tool as part of its package. Let’s run the following command to install Python version 3.6.

Code Listing 18: Installation of Python 3.6

[vagrant@amgr ~]$ sudo dnf install python36 -y

The output of the command should look like the output shown in Figure 14. We can also see that together with Python 3.6, this command also installs the pip and setuptools packages.

Installing Python 3.6

Figure 14: Installing Python 3.6

Once it’s installed, we will be working in a virtual environment, which we need to create first. This is very useful, as we can play around with packages installed by Python.

We need to create a folder called ansible, where we will keep the code, and afterward we will create and activate the virtual environment called avenv (which stands for ansible virtual environment, a random name chosen for convenience).

Code Listing 19: Creating the virtual environment

[vagrant@amgr ~]$ mkdir ansible

[vagrant@amgr ~]$ cd ansible

[vagrant@amgr ansible]$ python3 -m venv avenv

[vagrant@amgr ansible]$ source avenv/bin/activate

(avenv) [vagrant@amgr ansible]$

Activating the virtual environment will change your shell’s prompt to show what virtual environment you’re using, as you can see the (avenv) in front of the command prompt.

Note: Make sure to activate the environment every time before using Ansible by running source avenv/bin/activate in the ansible folder. To deactivate the virtual environment, just use the deactivate command.

Before installing Ansible, it is good to take the latest version of pip and setuptools by running the following command. We will also install a package called wheel, which will help us install Ansible.

Code Listing 20: Upgrade pip, setuptools, and wheel command

(avenv) [vagrant@amgr ansible]$ pip3 install --upgrade pip setuptools wheel

Installing Ansible

After pip and its dependencies have been properly installed and updated, we can install Ansible. Ansible is installed by the following command (inside the virtual environment).

Code Listing 21 : Installing Ansible with pip command

(avenv) [vagrant@amgr ansible]$ pip3 install ansible

Note: Installing Ansible also installs the dependencies such as jinja2, PyYAML, cryptography, and other packages.

The installation procedure is shown in the following figure.

Installation procedure of Ansible using pip

Figure 15: Installation procedure of Ansible using pip

When you wish to update Ansible, we can first check whether there is a newer version by using the following command.

Code Listing 22: Check for a newer version

(avenv) [vagrant@amgr ~]$ pip3 list --outdated

We can update to a newer version, if it exists.

Code Listing 23: Update Ansible command

(avenv) [vagrant@amgr ~]$ pip3 install -U ansible

The version of Ansible used in the examples in this book is 2.10.8.

Scroll To Top
Disclaimer
DISCLAIMER: Web reader is currently in beta. Please report any issues through our support system. PDF and Kindle format files are also available for download.

Previous

Next



You are one step away from downloading ebooks from the Succinctly® series premier collection!
A confirmation has been sent to your email address. Please check and confirm your email subscription to complete the download.