Creating a Load Balancer on top of AWS using Ansible.

Task Description:

Use Ansible playbook in AWS to Configure Reverse Proxy i.e. Haproxy and update it’s configuration file automatically on each time new Managed node (Configured With Apache Webserver) join the inventory.

Ansible is an open-source automation tool, or platform, used for IT tasks such as configuration management, application deployment, intraservice orchestration, and provisioning. Automation is crucial these days, with IT environments that are too complex and often need to scale too quickly for system administrators and developers to keep up if they had to do everything manually.

HAProxy is free, open source software that provides a high availability load balancer and proxy server for TCP and HTTP-based applications that spreads requests across multiple servers. It is written in C and has a reputation for being fast and efficient.

Lets Start →

Firstly launch the instances in the AWS.In my case i launched 2 webservers and 1 Load Balancer

Next lets update our ANSIBLE configuration file.. for AWS instance

Then create Inventory File in Controller Node.Here [awsWebapp] contains the ip of webserver instance and [awsLoadbalancer] contain the ip of Loadbalancer instance in AWS.

Create a Ansible Playbook

To make our code dynamic and automatically configure the Haproxy configuration file add the below code in haproxy configuration file in controller node.

Now letsRun the Playbook,

Now lets check in Loadbalancer.. cmd: vi /etc/haproxy/haproxy.cfg

php code created in Controller Node

Now when we provide the loadbalancer ip in the web browser we get the content from the backend web server (WEBAPP)

Here we can see when we refresh the page we can the source from the alternative Webserver this is possible bcoz of Load Balancer.

Finally we configured Haproxy on Top of AWS and Update it’s Configuration file automatically on each time new Managed Node join the inventory.

Github url: https://github.com/dileep-hub/Create-LoadBalancer-on-AWS-using-Ansible---12

Thanks for Reading…… 🙂

Passionate learner || Data Science Enthusiast || Django || Competitive Programmer