AUTOMATING HAPROXY USING ANSIBLE ON TOP OF AWS
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 over AWS using instance over there.
WHAT IS LOAD BALANCER?
A load balancer may be:
- A physical device, a virtualized instance running on specialized hardware or a software process.
- Incorporated into application delivery controllers (ADCs) designed to more broadly improve the performance and security of three-tier web and microservices-based applications, regardless of where they’re hosted.
- Able to leverage many possible load balancing algorithms, including round robin, server response time and the least connection method to distribute traffic in line with current requirements.
WHAT IS HAPROXY?
HAProxy is a free, amazingly fast and reliable solution offering high availability, load balancing, and proxying for TCP and HTTP-based applications. It is particularly suited for extremely high traffic web sites and powers quite a number of the world’s most visited ones. Over the years it has become the de-facto standard opensource load balancer, is now shipped with most mainstream Linux distributions, and is often deployed by default in cloud platforms. Its mode of operation makes its integration into existing architectures very easy and riskless, while still offering the possibility not to expose fragile web servers to the internet.
Let's Get Started
Step 1: Launch AWS Instances
I have launched 4 instances (3 instances for Backend Server, 1 for LoadBalancer )
Step 2: Adding IPs of instances in the inventory file (2 Groups: One for Haproxy and other one for backend servers):
vim /root/ip.txt
Ansible config:
Step 3: Lets check the connectivity with the instances:
ansible -m ping all
Step 4: Lets create the Ansible Playbook: (For reverse proxy and web server)
vim index.php
Step 5: To update HAProxy Configuration file automatically on each time new managed node join the inventory:
Step 6: Lets Run the Playbook
ansible-playbook play.yml
Lets Test the Web Pages: