Task 12

Pjore
4 min readMar 28, 2021

Hello Guys 🙋‍♀️ In this article we are going to perform the following task.

Task Description:

Use Ansible playbook to Configure Reverse Proxy i.e. Haproxy and update its configuration file automatically each time a new managed node joins inventory.

Let's start the practical…..

I am going to perform this practical on top of AWS. For that, you need to create an Ansible Setup On top of AWS.

Before starting the practical let's discuss Load Balancer.

What Is Load Balancer ???

Let's understand the concept of Load Balancer with the help of the following example.

Consider You have a Website and you host it by using Webserver. The client will use this webserver by using IP. The client will hit and the webserver will provide webpages to the client.

But the challenge is that normally any server has some hardcoded limit, which means at a single point of time only some client can connect to your webserver. And if at that point of time if the new client tries to connect to your webserver then they will not able to connect.

We can solve this challenge by configuring the same setup as previously so that we will never lose our client. but the new server contains new IP. So now we need to tell two IPs to the client. And in the future, if you need to create multiple setups then IPs also increased. So in this case we need to provide this multiple IP to the client. In this case, we don't know which IP is free so we need to check for each IP whether it is free or not and can we able connect to it or not. So this is the worst case.

So another solution for this is instead of giving all the IPs to the client, we launch one system and provide one fix IP to it. There will be multiple servers at the backend of this main server.

When any client wants to use the Website then they will use the IP of this system which is fixed and for a client, it acts as an actual Webserver. But in actual this server will send requests of clients to the backend web server, so for the backend web server, this system will act as a client. This is the reason it is also known as Reverse Proxy.

It is known as Load Balancer because it is distributing the load across all the backend webserver.

For this practical, I am going to use four instances. One will work as Controller Node on which we are going to run our all playbooks. One is for configuring Haproxy and Two will act as a Webserver.

Firstly you need to add IPs of the Target node inside the inventory of the Controller node.

If you are using AWS then do the following changes in the configuration file.

vim /etc/ansible/ansible.cfg

Let's write the playbook for Haproxy first.

Following is the Configuration file of haproxy which we need to mention inside the playbook. Do the necessary changes.

Let's run the playbook of Load Balancer

It has run successfully.

Let's write the playbook for Webserver Configuration

You need to create web pages also.

let's run this playbook now

It has run successfully.

Now if you check the configuration file of Haproxy now, you will see it has been updated

You can see It has been updated successfully.

Let's check whether the httpd service started or not on the webserver.

This is my Server 1. httpd service has successfully started.

You can see the httpd service successfully started on server 2 also.

When you connect to the browser make sure that your firewall has disabled. otherwise, you won't able to connect.

Our Task Completed Successfully!!!!!

Thanks For Reading😊😊😊

--

--