π˜Ύπ™Šπ™‰π™π™„π™‚π™π™π™€ π™ƒπ˜Όπ™‹π™π™Šπ™“π™”

Manali Jain
5 min readApr 7, 2021

--

12.1 Use Ansible playbook to Configure Reverse Proxy i.e. Haproxy and update its configuration file automatically each time a new Managed node (Configured With Apache Web Server) joins the inventory.

ARE YOU TIRED OF DOING EVERYTHING MANUALLY??

DO YOU WISH TO HAVE INTELLIGENT AUTOMATION??

YOUR WEB SERVER IS FAILING AND WORRYING YOU A LOT??

YOU ARE NOT ABLE TO MANAGE MULTIPLE WEBSERVER??

IN THIS BLOG I AM GOING TO TELL YOU ABOUT INTELLIGENT AUTOMATION i.e, ANSIBLE

Are you thinking about what is ANSIBLE??

ANSIBLE

Ansible is an automation tool that is built on top of Python.

Ansible is used for configuration management, provisioning, and orchestration.

Ansible is a Declarative tool that is used for Configuration Management.

Ansible is Agentless means Ansible should be installed on the controller node only and there is no need to install it on the target node.

Ansible Manages inventory for target nodes.

IS IT GOOD TO GIVE MULTIPLE IP ADDRESS TO CLIENT SO THAT THEY CAN ACCESS THE AVAILABLE NODE OR WE SHOULD GIVE ONLY ONE IP TO THEM??

The answer to the above question is very simple…

But tell me do you like messy things or clean and disciplined??

The Technical answer to this question is to use Lᴏᴀᴅ Bα΄€ΚŸα΄€Ι΄α΄„α΄‡Κ€ and here we are using the tool Hα΄€Pʀᴏxʏ.

LOAD BALANCER

Load Balancer is the service companies use to manage multiple nodes so that if one node is busy then they can use another one.

Load Balancer manages the traffic that is coming to the website.

Load Balancer stays between Client device and Backend Servers.

HAPROXY

HaProxy is a tool that works as a REVERSE PROXY. The Client accesses the HaProxy server and HaProxy will call the webserver to open the page but in this overall process, the Backend Server is not exposed publicly. Clients can only access the HaProxy Server; it cannot access the Backend Server and this is a good practice for security purposes.

Let’s jump to the Practical part…

MY FILES -

Created an inventory file that contains information about target nodes.

HaProxy configuration file contains the IP of Backend Server (Registration of backend server with HaProxy )

A webpage for testing purposes.

A YAML file that contains all the code for automation.

ANSIBLE INVENTORY

Inventory is the main part where all the target nodes' IPs are present. The inventory contains certain things about the target node -

  1. IP Address

2. Username

3. Password (if ssh key is not provided)

4. Connection type

The below image is of inventory file -

YAML CODE

Ansible Playbook is written in YAML language which will launch HaProxy server, web servers and in addition to this, it will configure HaProxy configuration file automatically.

  1. In the host, the Group name is given as β€œProxy” so that it will pick that particular IP for HaProxy configuration.
  2. Under the tasks, The first module used is β€œpackage” it will install haproxy software into the RHEL8 target node.
  3. The β€œtemplate” module will copy the file and it supports jinja2 so it will dynamically add web servers' IPs into it.
  4. The β€œservice” module will start or stop the service.
  5. SELinux is used because it will not allow us to access the page so change its mode to β€œPermissive”.
  6. The firewall will not allow web pages to access by public people so stop it.
  1. The hosts allow only WebServer groups for the configuration.
  2. Package module will install software like httpd, php, net-tools.
  3. The template module will copy the code to the target node.
  4. The service module will start the service.
  5. Change the mode of SELinux.

HAPROXY CONFIGURATION FILE -

HaProxy is using 8080 port numbers and web server IPs are registered dynamically by jinja2 code.

WEBPAGE

The webpage will show the IP of the web server so that we can easily test the code as to whether it’s working well or not.

RUN ANSIBLE PLAYBOOK

[ ansible-playbook -v file.yml ] is the command to run the ansible-playbook where [ -v ] is verbosity which gives extra information while running the playbook.

Run the Playbook

AFTER RUNNING PLAYBOOK WHAT CHANGES SEEN ??

CONFIGURATION FILE UPDATED

IP of the webserver is registered in the HAPROXY configuration file.

HAPROXY Configuration File

WEB PAGE COPIED

The webpage is copied in both the web servers.

webpage code
webpage code

OUTPUT

webpage
webpage

THANK YOU FOR READING THIS ARTICLE!!

SHARING IS CARING… KEEP LEARNING…

--

--

Manali Jain
Manali Jain

Written by Manali Jain

You are the only one person who can Change Yourself…

No responses yet