HAProxy Configuration Using Ansible on AWS

kore arvind
3 min readJan 5, 2021

TASK :

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.

🔰 What is Ansible?

📃 Ansible is a configuration management system written in Python using a declarative markup language to describe configurations. It is used to automate software configuration and deployment.

🔰 What is HAProxy ??

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.

🔰 HAProxy Architecture :

A reverse proxy accepts a request from a client, forwards it to a server that can fulfill it, and returns the server’s response to the client. A load balancer distributes incoming client requests among a group of servers, in each case returning the response from the selected server to the appropriate client.

⭐ Let’s Begin….. ⭐

♦️ CONTROLLER NODE ♦️

🔅 In Inventory File we mention IP of load balancer and IP of backend severs :

🔅 In configuration file of ansible :

Now,

ansible all  --list-hosts

Now, let’s check connectivity,

ansible all -m ping

🔅 In ansible playbook,

For configuring Load Balancer ;

For configuring backend servers as apache web servers ;

🔅 In HAProxy Configuration file,

🔅 Now, let’s run the play book,

♦️ MANAGED NODES ♦️

⭐ LOAD BALANCER ⭐

🔅 Let’s check whether Load Balancer is configured….

🔅 HAProxy Configuration file updated dynamically..

⭐ BACKEND SERVERS ⭐

🔅 SERVER-1 🔅

🔅 SERVER-2 🔅

Now, open any browser and provide URL as given below :

http://<load_balancer_IP>:>/<port_no>/<web_page>

Client doesn’t knows how many backend servers are there and by using load balancer IP it can see pages from backend servers.

Finally our Task is completed successfully !!!!😄✌🏻

GitHub URL : https://github.com/Vrukshali-26/ansible-aws-haproxy.git

Thanks for Reading !! 🙌🏻😁📃

🔰 Keep Learning !! Keep Sharing !! 🔰

--

--