Configure Haproxy using Ansible

Yukta chakravarty
2 min readJan 8, 2021

Task Description: Use Ansible playbook 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.

What is Reverse Proxy ?

A Reverse Proxy is a server which takes the requests from client and on behalf of client send it to the servers and then send the reply to clients. Here , clients don’t directly connect to servers. Reverse proxy also has Load Balancer that handles the traffic to the webapp

Reverse Proxy

Configure Haproxy:

Step 1: Install Haproxy

Step 2: Add webserver IPs to haproxy.cfg file located at /etc/haproxy/

Step 3: Start haproxy server

Inventory:

myweb group contains hosts that are webservers and mylb contains host for haproxy . Here, we are using VM’s

haproxy.cfg file

Here we are using for loop and we get IPs from inventory in myweb group. As soon as new IPs are added to myweb group in inventory that IP will be added in haproxy file when we run the playbook

Playbook:

When we use loadbalancer IP :5000 in browser we can see the website

--

--