How to Install and Configure ANSIBLE on RHEL8

Chetna Manku
3 min readJan 31, 2021

Ansible is a free and opensource automation tool that allows system administrators to configure and control hundreds of nodes from a central server without the need of installing any agents on the nodes.

To know more about Ansible, refer to this article — What is Ansible

Installation and Configuration of Ansible is a one time setup only.

INSTALLING ANSIBLE

Ansible is an agentless automation tool that by default manages machines over the SSH protocol.

  • You only need to install Ansible on Controller Node.
  • Controller Node then uses SSH (by default) to communicate with Managed or Target Nodes (those end devices you want to automate).
  • Ansible Playbooks or ad-hoc commands are used to manage the nodes.

🔰Controller Node Setup🔰

  • To install Ansible, you need Python pre-installed on your system.
  • By default, RHEL8 comes with Python3 installed.
  • You can check version of python3 using command :
# python -V
  • Now, install Ansible using pip3 command :
# pip3 install ansible
  • Check the version of Ansible installed using command :
# ansible --version
Output of Ansible version command
  • If above command runs successfully, Ansible is now installed on your RHEL8.
  • As you can see in above image, there is no configuration file is shown.
  • So, the next step is to create configuration file which will contain the location of Inventory.

Inventory is an initialization file that contains information about the hosts you are managing.

CREATING INVENTORY

  • Inventory contains information which is Hosts IP, Username of Hosts, Password of Hosts, and the Protocol used to connect to Hosts.
  • Create one file on your system, give any name, and this will be your inventory.
# vi <inventory_name>
  • You can add Hosts list in this inventory. As an example, one Host is added in the inventory.
Ansible Inventory

CONFIGURING ANSIBLE

  • First, create one folder which will be Ansible Configuration Folder.
# mkdir /etc/ansible
  • Now, create one configuration file in this configuration folder.
# vim /etc/ansible/ansible.cfg
  • Give the path of your inventory in this configuration file
[defaults]
inventory = <Path_of_inventory>
host_key_checking = False
  • Disable the host key checking feature. As by default, Ansible assumes you are using SSH keys to connect to remote systems i.e., hosts.
Content of Ansible Configuration File
Configuration file is created
  • Now you can see configuration file is created successfully!
  • To use the SSH connection type with passwords, you must install the sshpass program to run ansible commands and playbooks.
  • Download and Install the sshpass rpm file from browser as it doesn't exist in yum repository.

🔰Managed Node Setup🔰

  • You only need internet connectivity in managed node.
  • And rest of the work will be done automatically by Ansible from controller Node.

CHECK CONNECTIVIY

  • Check the connectivity of Controller Node to Hosts or Managed Nodes.
  • This command will ping to all the hosts added in the inventory.
ansible all -m  ping
  • Controller Node has connectivity to the managed nodes

You are all set to automate managed nodes using Ansible!

--

--