Configuration of HAProxy using Ansible → →
Tags: Haproxy, Ansible, Ansible Playbook

what is ansible?

Ansible is an open-source software provisioning, configuration management, and application-deployment tool enabling infrastructure as code. It runs on many Unix-like systems, and can configure both Unix-like systems as well as Microsoft Windows.

Configuration Management has always been an important task, mostly for installing, uninstalling, tracking and controlling changes in software or rather we can say in an Operating System. But manually configuring multiple no. of OS or servers is a tedious & error-prone job. Generally in companies, we have 100s or1000s or millions of servers depending upon the scale of the companies. Hence, there is no other way other than Automation.

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. It is written in C and has a reputation for being fast and efficient.

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. HAProxy acts as a Proxy server, as well as a LoadBalancer.

What is LoadBalancer?

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.

So now we are going to setup haproxy using ansible for this we have to need a manager node and need a haproxy server and also need a real server in which we are going to run our web sercer.

we have prefect connection with target nodes.

now we are going to configure 179 as a web server and 59 as a haproxy server.

we don’t have httpd software in target system so we are going to configure the webserver using ansible playbook.

we successfully done our task using ansible playbook. And we also able to access the site now on the top off this we are going to configure haproxy server.

now we have to download haproxy software in our machine for this we are going to use ansible playbook.

we successfully installed the software now we have to configure the haproxy for this we have a lot of way but simplest way we are going to use for this go to haproxy server and copy configuration file in manager node.

we copy the configuration file in manager node now configure the haproxy file.

in file we have to write the webserver ip and also tell which port we are bind with here I’m binding with port umber 8080-

we configure the haproxy server and also started haproxy services.

now port number 8080 is working in haproxy server .

Finally, the HAProxy is working great with both its features i.e., Reverse Proxy & LoadBalancing.