ANSIBLE: Haproxy Configuration over AWS using Ansible

 

CONFIGURATION OF HAPROXY 

USING ANSIBLE OVER AWS


Lets configure Reverse Proxy that is Haproxy using ansible Playbook.

Check this blog to know more about Haproxy : ANSIBLE : Configuration of Haproxy


As every server has a hard coded limit. At one point in time, only limited clients can connect to the web server. If more clients try to connect, the will get some error. That's why we are using Load Balancer. 

Here we want to achieve high availability and extra security for our web server using haproxy.

But the problem is that, if we need to add more servers, we can add them by adding their IP in inventory file and run the playbook.
But how Load balancer will come to know that more servers have been added????

For this we will have to manually update the configuration file of Haproxy. And manually updating is not good as we are using ansible.

So the solution is, we can use JINJA language to write code in configuration file. The best thing about this language is we can write some code in between the texts. We can use template module for uploading configuration file of Haproxy.

So my Ansible Playbook for Haproxy is :



This is my configuration file for Haproxy:



Here you can see i have used for loop in jinja to upload ip of webservers.

Here is code of my web page :



Here is ansible configuration file.
As we have to do this over AWS instance so remote user and private key is given.
For this, first upload the private key of aws instance to your workspace then give path here in ansible configuration file.


This is the output I got after running the playbook:



Now to check the load balancer is working properly or not, search for <ip>:8888 of load balancer on any browser .



Here you can see my Load balancer is working. I'm getting ip of my backend server that means this webpage is running on my backend server.


Hope you like this..

Comments

Popular posts from this blog

Automation Using Python

Chat Server using UDP

NETWORK TOPOLOGY