Configuring Reverse Proxy i.e. Haproxy and Update it’s configuration file automatically via Ansible

Shivansh Srivastava
3 min readDec 27, 2020


HAProxy is a 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.


HAProxy, which stands for High Availability Proxy, is a popular open-source software TCP/HTTP Load Balancer and proxying solution which can be run on Linux, Solaris, and FreeBSD. Its most common use is to improve the performance and reliability of a server environment by distributing the workload across multiple servers (e.g. web, application, database). It is used in many high-profile environments, including GitHub, Imgur, Instagram, and Twitter.

In this guide, we will provide a general overview of what HAProxy is, basic load-balancing terminology, and examples of how it might be used to improve the performance and reliability of your own server environment.

HAProxy Terminology

There are many terms and concepts that are important when discussing load balancing and proxying. We will go over commonly used terms in the following sub-sections.

Before we get into the basic types of load balancing, we will talk about ACLs, backends, and frontends.

Ansible-playbook for configuring two servers and a loadbalancer.

Template for haproxy configuration file. Bind to set a port for haproxy, and jinja code for updating inventory file for servers.

Running playbook on the controller node.

Servers running on the web.

Now, we can see that by using the same socket we can set up two servers behind the scene. The backend has two servers of IP and While the frontend exposed to the client is only one IP 192.168.43,132. Now we have successfully configured loadbalancer architecture via Ansible playbook for automation.

Thank you, everyone.
Feel free to contact me in case of any doubts @



Recommended from Medium


See more recommendations