Automating HAProxy using Ansible
Task Description 📃
12.1 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 Load Balancer ?
Load balancing refers to efficiently distributing incoming network traffic across a group of backend servers, also known as a server farm or server pool.
A load balancer acts as the “traffic cop” sitting in front of your servers and routing client requests across all servers capable of fulfilling those requests in a manner that maximizes speed and capacity utilization and ensures that no one server is overworked, which could degrade performance. If a single server goes down, the load balancer redirects traffic to the remaining online servers. When a new server is added to the server group, the load balancer automatically starts to send requests to it.
In this manner, a load balancer performs the following functions:
- Distributes client requests or network load efficiently across multiple servers
- Ensures high availability and reliability by sending requests only to servers that are online
- Provides the flexibility to add or subtract servers as demand dictates
What is HAProxy?
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.
Let's Get Started
We have ip.txt which contains IPs of the managed node:
For load Balancer: 192.168.43.34
For Backend Server: 192.168.43.143
vim /root/ip.txt
Checking the connectivity with the managed nodes:
ansible -m ping all
Ansible Playbook:
vim play.yml
To update HAProxy Configuration file automatically on each time new managed node join the inventory:
Lets Run the Playbook:
ansible-playbook play.yml
Now, we can see that Configuration file is updated dynamically:
Thank You for Reading !!!