Deploying a Load Balancer and multiple Web Servers on AWS through ANSIBLE!

This article will help you to know that How we can launch HAPROXY Loadbalancer and Multiple WEBSERVERS on the top of AWS Cloud with the help of ANSIBLE.

Ansible :

Ansible is a radically simple IT automation engine that automates cloud provisioning, configuration management, application deployment, intra-service orchestration, and many other IT needs.

Designed for multi-tier deployments since day one, Ansible models your IT infrastructure by describing how all of your systems inter-relate, rather than just managing one system at a time.

It uses no agents and no additional custom security infrastructure, so it’s easy to deploy — and most importantly, it uses a very simple language (YAML, in the form of Ansible Playbooks) that allow you to describe your automation jobs in a way that approaches plain English.

Load Balancer :

A load balancer is a device that acts as a reverse proxy and distributes network or application traffic across a number of servers. Load balancers are used to increase the capacity (concurrent users) and reliability of applications. They improve the overall performance of applications by decreasing the burden on servers associated with managing and maintaining application and network sessions, as well as by performing application-specific tasks.

HAProxy (High Availability Proxy) is a TCP/HTTP load balancer and proxy server that allows a webserver to spread incoming requests across multiple endpoints. This is useful in cases where too many concurrent connections over-saturate the capability of a single server.

Now Let’s start the Configuration..


First, we have to update the inventory file-


Create the playbook-

So this is our playbook which we are going to use for configuring Load Balancer or haproxy.

After writing the playbook now you have to make some changes in the configuration file of haproxy and the configuration file is located at /etc/haproxy/haproxy.cfg.

Now comes the very important part of this task, and that task is to set the configuration file. Now first you have to create a file named haproxy.cfg in your same directory where your playbook is located, and the content of this file is same as the content of original haproxy.cfg which is located at /etc/haproxy/haproxy.cfg only with some small changes in it and this small change is shown in the image below..


Run the playbook-

This shows that without any error our playbook runs successfully and the Load Balancer is configured to.


Now I am going to web-browser to check the content .

Both page came from different server….

By seeing this output we can conclude that , haproxy work properly in loadbalancer.



Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store