Configuring reverse proxy with Ansible and also updating Haproxy conf file each time new node(aws instance)join inventory

This blog is Something about Configuring Reverse Proxy i.e. Haproxy and updating it’s configuration file automatically on each time new Managed node (Configured With Apache Webserver) join the inventory on AWS.

So What Haproxy actually is..?

lets begin..

🔹Firstly we have to update the Ip addresses in Inventory file of controller node on which we want to configure something

So here in this Inventory I have updated 2 Ip’s , one for Loadbalancer and another one for Backend server.

#vim /etc/myhosts.txt

🔹Ansible Configuration file

#vim /etc/ansible/ansible.cfg

🔹Checking Connectivity of Controller node with Managed nodes

#ansible -m ping all

🔹Ansible playbook

host: lb ➯ For Loadbalancer

host: server ➯ For Backend server

➽Haproxy file configuration

🔹 Running Playbook

Now we are done with the Controller node configuration..!!

Lets check it manually on managed node.

✨Managed node

🔯Load balancer🔯

We can see that Haproxy is installed and configured here and also Haproxy services are running very fine.

Now lets check the Haproxy configuration file also.

⭐Haproxy config file⭐

Yes…here you could see that this file is dynamically updated with the Ip of the Backend server.

🔹checking on browser

Note: You can match the Ip of backend server here ⬇

Now we can add as many new instances as managed nodes to configure them as a backend servers by just updating their IP’s to the inventory file and dynamically it will update it to the configuration file of haproxy.

So let’s configure one more backend server as a apache httpd webserver with the same webpage by just adding its IP i.e 13.234.37.198 to the inventory file.

🔹Adding one new ip to inventory

Now we just have to run the playbook again and thats it.

This server is launched successfully.

Lets check whether this Backend server is updated in Haproxy file of loadbalancer or not.

🔹Checking haproxy config file

You could see both the ip’s of the both the servers are updated here dynamically.

Note: you can match the ip of newly added server from here⬇

🔹Finally ..lets check both the servers on browser

When we hit firstly to the loadbalancer we will get one of the server’s webpage ⬇

But when we hit second time to the Loadbalancer we will get another server’s webpage with the same content.

Hence verified..!!

✨Loadbalancer is working very fine…✨

Upcoming Engineer