Ansible. Introducing Ansible

In this Ansible article series, you will learn all the skills you need to manage and automate IT infrastructure operations with Ansible.

What is Ansible?

Ansible is an open source configuration management, software provisioning, and application deployment tool that makes it easy to automate application deployment and IT infrastructure operations.

Ansible is very lightweight, easy to set up, and does not require resources because it does not need an agent to work (agentless), unlike other automation tools like Puppet, which is agent-based and a little tricky to set up.

This explains why Ansible is growing in popularity every day and becoming a transition automation tool for many businesses.

In science fiction, Ansible refers to a hypothetical device that allows users to communicate instantly over long distances; that is, the communication device is faster than the speed of light. Now you know where Ansible got its name from.

Creating your playground

To get the most out of this series and follow it painlessly, I advise you to use the same setting as I did.

We have created one RHEL (Red Hat Enterprise Linux) 8 virtual machine to serve as the control node. A management node, as the name suggests, is basically a server that is used to manage other remote hosts (managed nodes).

We have created three CentOS 8 VMs for managed nodes: node1, node2 and node3. We also built Ubuntu 18.04 for the last managed node.

We don’t have enough resources on the computer to create all these virtual machines without crashing the computer. So, we used Microsoft Azure on all virtual machines, as you can see in the screenshot below:

You can use any other cloud server vendor.

Installing Ansible

Ansible relies on SSH and Python to do all the automation magic, so you only need to install Ansible on the control node and make sure OpenSSH and Python are installed on both the control and managed nodes.

In short, you don’t need to install Ansible on managed nodes!

We are now going to show you how to install Ansible on various systems.

Installing Ansible on RHEL Systems

We will first show you how to install Ansible on a RHEL 8 system.

Log in to your control node and switch to the root user:

[[email protected] ~]$ sudo su -
Last login: Tue Oct 20 01:05:00 UTC 2020 on pts/0

By checking the Linux version information, you can see that we are running RHEL 8.2 and going to use it as a management node:

[[email protected] ~]# cat /etc/redhat-release
Red Hat Enterprise Linux release 8.2 (Ootpa)

To install Ansible on a RHEL 8 system, you first need to register your system using the subscription-manager command:

[[email protected] ~]# subscription-manager register
Registering to:
Password: xxxxx
The system has been registered with ID: 1d8ace59-c140-4f8c-b4bb-b4cd0f4fb811
The registered system name is: control

You will be prompted for a username and password, as you can see, if you don’t have a Red Hat account, you can create an account and get a free trial.

Then you have to attach the new subscription using the following command:

[[email protected] ~]# subscription-manager attach --auto
Installed Product Current Status:
Product Name: Red Hat Enterprise Linux for x86_64
Status: Subscribed

Product Name: Red Hat Enterprise Linux for x86_64 - Extended Update Support
Status: Subscribed

Note that you could register and attach a subscription with one command:

subscription-manager register --username=<USER_NAME> --password=<PASSWORD> --auto-attach

We now have access to all the RHEL 8 repositories. You can view all of the available Ansible repositories by running the following command:

[[email protected] ~]# yum repolist all | grep ansible
ansible-2-for-rhel-8-x86_64-debug-rpms Red Hat Ansible E disabled
ansible-2-for-rhel-8-x86_64-rpms Red Hat Ansible E disabled
ansible-2-for-rhel-8-x86_64-source-rpms Red Hat Ansible E disabled
ansible-2.8-for-rhel-8-x86_64-debug-rpms Red Hat Ansible E disabled
ansible-2.8-for-rhel-8-x86_64-rpms Red Hat Ansible E disabled
ansible-2.8-for-rhel-8-x86_64-source-rpms Red Hat Ansible E disabled
ansible-2.9-for-rhel-8-x86_64-debug-rpms Red Hat Ansible E disabled
ansible-2.9-for-rhel-8-x86_64-rpms Red Hat Ansible E disabled
ansible-2.9-for-rhel-8-x86_64-source-rpms Red Hat Ansible E disabled

Now find the repository for the newest version of Ansible and enable it. As of this writing, ansible-2.9 is the latest version, so we’re going to enable ansible-2.9-for-rhel-8-x86_64-rpms using the yum_config_manager command like this:

[[email protected] ~]# yum-config-manager --enable ansible-2.9-for-rhel-8-x86_64-rpms
Updating Subscription Management repositories.

Now you can verify that the Ansible repository is indeed enabled by listing all enabled repositories on your system:

[[email protected] ~]# yum repolist enabled
Updating Subscription Management repositories.
repo id                                                         repo name
ansible-2.9-for-rhel-8-x86_64-rpms Red Hat Ansible Engine 2.9 for RHEL 8 x86_64 (RPMs)
microsoft-azure-rhel8-eus Microsoft Azure RPMs for RHEL8 Extended Update Support
rhel-8-for-x86_64-appstream-eus-rhui-rpms Red Hat Enterprise Linux 8 for x86_64 - AppStream - Extended Update Support from RHUI (RPMs)
rhel-8-for-x86_64-appstream-rpms Red Hat Enterprise Linux 8 for x86_64 - AppStream (RPMs)
rhel-8-for-x86_64-baseos-eus-rhui-rpms Red Hat Enterprise Linux 8 for x86_64 - BaseOS - Extended Update Support from RHUI (RPMs)
rhel-8-for-x86_64-baseos-rpms Red Hat Enterprise Linux 8 for x86_64 - BaseOS (RPMs)

All this preliminary work is done. Now you can finally install Ansible:

[[email protected] ~]# yum install -y ansible

After the installation is complete. You can verify that Ansible is indeed installed by running the command:

[[email protected] ~]# ansible --version
ansible 2.9.14
config file = /etc/ansible/ansible.cfg
configured module search path = ['/root/.ansible/plugins/modules', '/usr/share/ansible/plugins/modules']
ansible python module location = /usr/lib/python3.6/site-packages/ansible
executable location = /usr/bin/ansible
python version = 3.6.8 (default, Dec  5 2019, 15:45:45) [GCC 8.3.1 20191121 (Red Hat 8.3.1-5)]

Awesome! You have now successfully installed Ansible on RHEL 8. We’re sure you might think it was a lengthy process!

Installing Ansible on CentOS

On CentOS, Ansible is provided by the EPEL (Extra Package for Enterprise Linux) repository.

You can install and enable the EPEL repository by installing the epel-release package as follows:

[[email protected] ~]# yum install -y epel-release

Now you can install ansible:

[[email protected] ~]# yum install -y ansible

Keep in mind that we have installed Ansible on one of the managed nodes here (node1) for educational purposes only; you only need to install Ansible on the control node.

Installing Ansible on Ubuntu

On Ubuntu, you need to ensure that the repository of the desired Ansible version is enabled on your system.

You can add and enable the ansible-2.9 ppa repository using the following command:

[email protected]:~# apt-add-repository --yes --update ppa:ansible/ansible-2.9

Finally, you can install Ansible on Ubuntu:

[email protected]:~# apt-get -y install ansible

This brings us to the end of our first tutorial in this RHCE Ansible preparation series. Stay tuned for updates in the next article as you learn how to set up Ansible and run some really cool Ad-Hoc Ansible commands.