In this Ansible series, you will learn all the skills you need to manage and automate your IT infrastructure operations with Ansible.
Also, all the objectives for the RHCE (Red Hat Certified Engineer) EX294 exam will be covered in this series. This means that you will be fully prepared to pass the EX294 exam and become a Red Hat Certified Engineer if you follow the series.
What is Ansible?
Ansible is an open-source configuration management, software provisioning, and application deployment tool that makes automating your application deployments and IT infrastructure operation very simple.
Ansible is very lightweight, easy to configure, and is not resource hungry because it doesn’t need an agent to run (agentless) unlike other automation tools, for example, Puppet which is agent based and is a bit complex to configure.
This explains why Ansible is growing in popularity each day and becoming the goto automation tool for many enterprises.
In science fiction, the word Ansible refers to a hypothetical device that enable uses to communicate instantaneously across great distances; that is, a faster-than-light communication device. Now you know where Ansible got its name inspiration.
Creating Your Playground
To make the most out of this series and follow along painlessly, I advise you to use the same setup that I am using.
I created one RHEL (Red Hat Enterprise Linux) 8 virtual machine that would serve as the control node. A control node is, as its name suggest is basically a server that is used to control other remote hosts (managed nodes).
I created three CentOS 8 virtual machine for managed nodes: node1, node2, and node3. I also created an Ubuntu 18.04 for the last managed node.
Here is a diagram that summarizes the whole setup:
I don’t have enough resources on my computer to create all these virtual machines without my computer crashing. So, I have used Microsoft Azure all the virtual machines as you can see in the screenshot below:
Ansible relies on SSH and Python to do all the automation magic and so you only need to install Ansible on the control node and make sure that OpenSSH and Python is installed on both the control and the managed nodes.
Long story short, you don’t need to have Ansible installed on the managed nodes!
Now, I am going to show you how to install Ansible on a variety of systems.
Installing Ansible on RHEL Systems
I will first start by showing you how to install Ansible on a RHEL 8 system as this series is primarily targeting all the RHCE exam objectives.
Login 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
Checking Linux version information, you can see I am running RHEL 8.2 and I am going to use this as control node:
[[email protected] ~]# cat /etc/redhat-release Red Hat Enterprise Linux release 8.2 (Ootpa)
To get Ansible installed on a RHEL 8 system, you first have to register your system with the subscription-manager command:
[[email protected] ~]# subscription-manager register Registering to: subscription.rhsm.redhat.com:443/subscription Username:xxxxx 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 a password as you can see, if you don’t have a Red Hat account, you can create an account and obtain a free trial.
You would then to attach the new subscription with 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
Notice that you could have registered and attached the subscription in a single command:
subscription-manager register --username=<USER_NAME> --password=<PASSWORD> --auto-attach
Now we have access to all the RHEL 8 repositories. You can list all 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 newest Ansible version repository and enable it. At the time of writing this, ansible-2.9 is the latest version and so I am going to enable the ansible-2.9-for-rhel-8-x86_64-rpms with the yum_config_manager command as follows:
[[email protected] ~]# yum-config-manager --enable ansible-2.9-for-rhel-8-x86_64-rpms Updating Subscription Management repositories.
You can now verify that the Ansible repository is indeed enabled by listing all the 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. You can now 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. I am sure you may be thinking that was a lengthy process!
On the bright side, there will be no internet access on the exam, which means, your control system will come equipped with all the repositories that you will need, and so you won’t have to worry about using the subscription manager.
But it’s better to be prepared than to be surprised, always remember this!
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 repo 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 installed Ansible on one of the managed nodes here (node1) only for learning purposes; you only need to install Ansible on the control node.
Installing Ansible on Ubuntu
On Ubuntu, you need to make sure you have the desired Ansible version repository enabled on your system.
You can add and enable 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 takes us to end of our first tutorial in this RHCE Ansible preparation series. Stay tuned for next tutorial as you are going to learn how to configure Ansible and get to run some really cool Ad-Hoc Ansible commands.