๐—œ๐—ป๐˜๐—ฟ๐—ผ๐—ฑ๐˜‚๐—ฐ๐˜๐—ถ๐—ผ๐—ป ๐˜๐—ผ ๐—”๐—ป๐˜€๐—ถ๐—ฏ๐—น๐—ฒ,๐‡๐จ๐ฐ ๐“๐จ ๐ˆ๐ง๐ฌ๐ญ๐š๐ฅ๐ฅ ๐š๐ง๐ ๐‚๐จ๐ง๐Ÿ๐ข๐ ๐ฎ๐ซ๐ž ๐€๐ง๐ฌ๐ข๐›๐ฅ๐ž.

Rohit Raut
5 min readNov 25, 2020

What is Ansible?

Ansible is an open-source automation engine that automates software provisioning, configuration management, and application-deployment tool by enabling infrastructure as code. It runs on many Unix-like systems and can configure both Unix-like systems as well as Microsoft Windows. It includes its own declarative language to describe system configuration.

The architecture of Ansible:

How Ansible Works?

There can be multiple remote machines that are handled by one control Node. So, for managing remote machines. Ansible is agentless so we donโ€™t require any extra software on managed Node.

The Ansible management node is the controlling node, which controls the entire execution of the Playbook. Itโ€™s the node from which you are running the installation, and the inventory file provides the list of the host where the modules need to be run. The management node makes ssh connection, and then it executes the modules on the host machines and installs them to reach the desired state of the computer. It removes the modules once they are installed. So thatโ€™s how ansible works.

Installation Process

Pre-requisites:-

โœ” Yum should be configured

โœ” To Configure Ansible and for verification we need two RHEL 8 VM

Mainly, there are two types of machines when we talk about deployment โˆ’

  • Control machine โˆ’ Machine from where we can manage other machines. here IP: 192.16.43.85
  • Remote machine โˆ’ Machines that are handled/controlled by a controller Node. IP: 192.168.43.200

Ansible Software needs to be installed only on the controller node

There can be multiple remote machines that are handled by one control Node. So, for managing remote machines we have to install Ansible on the control machine. Ansible is agentless so we donโ€™t require any extra software on managed Node.

Ansible is build using python and the python library contains ansible software and to install any python library we use the pip3 command.

1. we need to install python

yum install python3

2. Install Ansible using pip

To check the version of Ansible.

ansible --version
Ansible is Successfully Installed.

Install sshpass software

Ansible uses this software to login into a remote user that has password-based authentication.

yum install sshpass -y

Ansible Configuration and Inventory File.

Configuration File:

filename must be ansible.cfg

Ansible check configuration file at three different places and the default location is/etc/ansible/ansible.cfg

1st one has the highest priority.

1. The current directory from where you are running the ad-hoc command or playbook.

2. The home directory of the user

3. The default location: /etc/ansible/ansible.cfg

Inventory File.

The inventory file is like a database used to tell ansible information about hosts/managed Nodes. It can be created anywhere in the Operating System.

There are two types of Inventory Files:

  1. Static inventory involves manually adding hosts.
  2. Dynamic inventory uses scripts to populate an inventory with hosts.

In each conf file, we have to specify the location of inventory or you can use -i option in each command to give the location of the inventory file.

Letโ€™s set up an configuration and inventory file.

Inventory File

Create an inventory file and add host entries.

Configuration File.

When we install ansible using pip then manually we have to create ansible.cfg file. for this

Configure Ansible command Defaults in the conf file

To connect to hosts Ansible uses SSH protocol and when we trying to log in the first time it checks for host keys and gives this error.

To disable to we have to add

host_key_checking = false

Verification using ansible ping module

ansible all -m ping

if everything is correct it returns with pong.

Thatโ€™s all, Congratulationโ€™s we have successfully configured ansible.๐Ÿคฉ

How Ansible Works?

There can be multiple remote machines that are handled by one control Node. So, for managing remote machines. Ansible is agentless so we donโ€™t require any extra software on managed Node.

The Ansible management node is the controlling node, which controls the entire execution of the Playbook. Itโ€™s the node from which you are running the installation, and the inventory file provides the list of the host where the modules need to be run. The management node makes ssh connection, and then it executes the modules on the host machines and installs them to reach the desired state of the computer. It removes the modules once they are installed. So thatโ€™s how ansible works.

What is Playbook?

A play is an ordered set of tasks run against hosts selected from your inventory. A playbook is a text file containing a list of one or more plays to run in a specific order. Plays allow you to change a lengthy, complex set of manual administrative tasks into an easily repeatable routine with predictable and successful outcomes.

In a playbook, you can save the sequence of tasks in a play into a human-readable and immediately runnable form. The tasks themselves, because of the way in which they are written, documents the steps needed to deploy your infrastructure.

A playbook consist of multiple plays is in a text file written in YAML format and is normally saved with the extension yml. Each play must have at list two keys

  1. hosts: โ€œhostsโ€ is an attribute, which specifies the hosts against which the plays will be run by ansible.
  2. Tasks: it consists of a list of tasks/configurations applied on hosts.

For practical of Playbook โ†’

In this article, I have taken an example of a playbook to configure Apache Webserver Using Ansible.

Hope This will Help you all.

Thank You For Reading!!๐Ÿ˜‡๐Ÿ˜‡๐Ÿ˜‡

Connect with me On LinkedIn for further queries.

--

--