Ansible Tutorial for Automation

What is Ansible ?

Ansible is an awesome automation tool for Linux sysadmins. It is an open source configuration tool which allows sysadmins to manage hundreds of servers from one centralize node i.e Ansible Server. Ansible is the preferred configuration tool when it is compared with similar tools like Puppet, Chef and Salt because it doesn’t need any agent and it works on SSH and python.

How to Install Ansible in CentOS 8 and RHEL 8

A) Ansible Installation in CentOS 8  

Ansible package is not available in default CentOS 8 package repository. so we need to enable EPEL Repository by executing the following command,

[ ~] $ sudo dnf install -y

Once the epel repository is enabled, execute the following dnf command to install Ansible

[ ~] $  sudo dnf install ansible

Once the ansible is installed successfully, verify its version by running the following command

[ ~] $  sudo ansible --version

B) Ansible Installation in RHEL 8  

If you have a valid RHEL 8 subscription then use following subscription-manager command to enable Ansible Repo,

[ ~] $ sudo subscription-manager repos --enable ansible-2.8-for-rhel-8-x86_64-rpms

Once the repo is enabled then execute the following dnf command to install Ansible,

[ ~] $ sudo dnf install ansible -y

Once the ansible and its dependent packages are installed then verify ansible version by executing the following command,

[ ~] $ sudo ansible --version

How to Use Ansible Automation Tool?

When we install Ansible using yum or dnf command then its configuration file, inventory file and roles directory created automatically under /etc/ansible folder.

So, let’s add a group with name “testserver” and under this group add 2 serevrs ip address  in /etc/ansible/hosts file

[ ~] $ sudo vi /etc/ansible/hosts

Save & exit file.

Once the inventory file (/etc/ansible/hosts) is updated then exchange your user’s ssh public keys with remote systems which are part of “testserver” group.

Let’s first generate your local user’s public and private key using ssh-keygen command,

[ ~] $ ssh-keygen

Now exchange public key between the ansible server and its clients using the following command,

[ ~] $ ssh-copy-id ansbile@
[ ~] $ ssh-copy-id ansbile@

Now let’s try couple of Ansible commands, first verify the connectivity from Ansible server to its clients using ping module,

[ ~] $ ansible -m ping "testserver"

Note: If we don’t specify the inventory file in above command then it will refer the default hosts file (i.e /etc/ansible/hosts)

In output if you see SUCCESS then ping was successful

That’s all from this article, we have successfully demonstrated on how to install and use Ansible on CentOS 8 and RHEL 8 System.

Download Ansible Documentation Guide