Configure Reverse Proxy i.e. HAproxy and update its configuration file automatically each time a new Managed node (Configured With Apache Webserver) joins the inventory. (using ansible-playbook)
This article will give you an idea of how can you use jinja templating to make a dynamic configuration file for ansible.
First of all, let’s get a brief idea of what Ansible and HAProxy are.
Ansible
It is an automation tool specialized for Configuration Management and its modules make it different from other tools that use scripts. Ansible used the declarative language approach which gives the users ease of use.
HAProxy
It is a product that helps to set up a reverse proxy and load balancer. We can give details about the backend servers and this product takes care of forwarding the client requests to the servers with a load-balanced setup.
Let’s see how to set up this HAProxy and WebServers.
Ansible inventory:
For now, we just have one web server, we’ll add more web servers later and see how ansible dynamically adds them to the HAProxy’s configuration file to extend the number of backend servers behind the load balancer.
Web Server conf file
Webpage (index.php)
Web Server set-up ansible-playbook
Running the playbook for webserver configuration
HAproxy conf file
HAProxy set-up ansible-playbook
Running the playbook for HAproxy configuration
Accessing the webpage
We can see that even though we put the URL of load_balancer’s IP, but we get the IP of the backend server on the webpage.
This is how we set up the Backend Server and Load Balancer.
Let’s now make the new managed node join the inventory and see how HAproxy adds it to its conf file and do the load balancing.
Running the HAProxy ansible-playbook again
Let’s now access the webpage and see how HAProxy balances the load
On Reloading,
So, we see that on reloading the request got forwarded to another webserver.
This was all about the “Configure Reverse Proxy i.e. HAproxy and update its configuration file automatically each time a new Managed node (Configured With Apache Webserver) joins the inventory. (using ansible-playbook)”
Thank You.. :)
#vimaldaga #righteducation #educationredefine #rightmentor #worldrecordholder #linuxworld #makingindiafutureready #righeudcation #arthbylw #ansible #facts #inventory #webserver