Configuring Reverse
Proxy and update it’s configuration
file automatically on each time new Managed node join the inventory on local machine

Harsh Agrawal
3 min readMay 12, 2021

This blog will explain you how to setup reverse proxy and to configure it automatically every time you attach new managed node.

Below are the machines I have launched according to above picture -

* Namenode -

rhel8_arth — 192.168/29.202 — machine on which ansible script will run.

* Datanode

rhel-exp-2–192.168.29.225 — machine on which haproxy will configure.

rhel-cli — 192.168.29.201 — machine-1 on which web server-1 will run.

rhel-cl-2–192.168.29.24 — machine-2 on which web server-2 will run.

Now go to your namenode(rhel8_arth) machine and configure its inventory file by as -

Make a directory and put your yml file and cfg(configuration file of haproxy)

both file in that directory.

Below is the script …

..

Do the changes in haproxy.cfg.j2 file as show below.

I have used jinja code so that it can dynamically update it self to configure haproxy.

Bind keyword as shown in below rectangle shows that haproxy runs on 8081 port number.

second rectangle is use to update ip address of the instances where web server runs.

After all above configuration run the script

ansible-playbook lb.yml

As the script runs successfully, now go to instance where you run haproxy server and web servers and check their status by the command —

systemctl status haproxy
systemctl status httpd
instance running haproxy
instance running web server 1
Instance running web server 2

Now go to browser and check whether haproxy server is running or not

ip_address_of_haproxy_instance:port_number/index.html

Thank you

Harsh Agrawal

https://github.com/HarshAgrawal25/Ansible/tree/master/Ansible%20playbook%20for%20haproxy%20and%20load%20balancer

--

--