Ansible playbook to Configure Reverse Proxy
Anudeep Nalla
Opensource Contributer | Platform Engineer | EX-NPCI | RHCA Level III | OpenShift | CEPH | CK{S,A,AD} | 3x Microsoft Certified | AWS CSA | Rancher | Nirmata | DevOps | Ansible | Jenkins | DevSecOps | Kyverno | Rook-Ceph
Task Description
12.1 Use Ansible playbook to Configure Reverse Proxy i.e., HAProxy and update its configuration file automatically on each time new Managed node (Configured with Apache Webserver) join the inventory.
1)??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.
Modern high?traffic websites must serve hundreds of thousands, if not millions, of concurrent requests from users or clients and return the correct text, images, video, or application data, all in a fast and reliable manner. To cost?effectively scale to meet these high volumes, modern computing best practice generally requires adding more servers.
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.
Benefits of Load Balancing
·???????Reduced downtime
·???????Scalable
·???????Redundancy
·???????Flexibility
·???????Efficiency
1)??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.
Ansible:
Ansible?is a software tool that provides simple but powerful automation for cross-platform computer support. It is primarily intended for IT professionals, who use it for application deployment, updates on workstations and servers, cloud provisioning, configuration management, intra-service orchestration, and nearly anything a systems administrator does on a weekly or daily basis. Ansible does not depend on agent software and has no additional security infrastructure, so it's easy to deploy
So, you are going to design this architecture using the Automation tool Ansible.
Pre-requisite
To configure the above architecture, you have some pre-requisite which are mentioned here.
1.???Configured Ansible Controller node
2.?????4 or more than 4 Virtual machines (i.e., MN1, MN2, MN3, LB)
Step1: We have Installed the ansible in CN and setup the ansible.cfg file in /etc/ansible
Set the Inventory.txt
Check the setup using:?
ansible all --list-hosts
check that all?managed nodes?are pingable or not, Using:
ansible all -m ping
Create a workspace and copy?haproxy.cfg?into the?controller node.?
领英推荐
# Binding with port 8080
Open the?haproxy.cfg?file in the controller node and bind the?port 8080.
Also, write the jinja code to update the?haproxy.cfg?file to perform Load Balancer Dynamically.
Step2: Create an?Ansible playbook?to configure the Web servers and load balancer.
Check the Syntax of the playbook using:
ansible-playbook --syntax-check <playbook_name>.yml
Now, Run the playbook using:
ansible-playbook <playbook_name>.yml
Check the haproxy.cfg?file is updated, in LB VM using:
Vim /etc/haproxy/haproxy.cfg
You can see in the above screenshot, the?haproxy.cfg?file is updated.
Let’s check the Load Balancer is working or not.
It works well with two web servers.
so let's look at how to connect the load balancer to a new web server, if you want to add one or more web servers now.
Open your inventory file in CN and add the information of New OS.
Now, Run the playbook again using:
???? ansible-playbook <playbook_name>.yml
Check the haproxy.cfg?file is updated, in LB VM using:
Vim /etc/haproxy/haproxy.cfg
Now, verify the setup.
Load Balancer is also working great with all the three web servers.
GitHub link:?
Thank You