Configure Reverse Proxy Using Ansible Playbook

What is Reverse Proxy?

A reverse proxy server is a type of proxy server that typically sits behind the firewall in a private network and directs client requests to the appropriate backend server. A reverse proxy provides an additional level of abstraction and control to ensure the smooth flow of network traffic between clients and servers.

Reverse Proxy Server

Why We Need a Reverse Proxy?

You have a web server that can manage 100 clients at a time. Suddenly the requests to that particular server increase by 100 percent. It’s likely that the website will crash or be terminated. To avoid this situation, set up a target web server. In this scenario, the client never goes to the target web server. Instead, their request goes to the master server, and the master server sends the request to the target web server. When the target web server replies to the master web server, which is known as a reverse proxy.

What is The Round Robin?

“Roundrobin” load balancing is one of the simplest methods for distributing client requests across a group of servers. Going down the list of servers in the group, the “roundrobin” load balancer forwards a client request to each server in turn.

For achieving this setup we are going to use the Haproxy server. So without wasting any time let’s jump on practical.

My Ansible inventory file is shown here. For this setup, one computer(mylb group) will be configured as a load balancer and another two computers(webserver group) will get configured as Web servers.

Inventory file

Ansible Configuration file:

In My Case my inventory file and ansible configuration file store in one kind of workspace /ansible direcoty indise this we store inventory file & ansible.cfg file.

Ansible.cfg file

What is Apache Httpd WebServer?

This is the most popular web server in the world developed by the Apache Software Foundation. Apache web server is an open source software and can be installed on almost all operating systems including Linux, UNIX, Windows, FreeBSD, Mac OS X and more. About 60% of the web server machines run the Apache Web Server.

Step-1: Configure Webserver and demonstrate the Ansible Playbook

Webserver Playbook

Step-2: Demonstrate the Reverse Proxy Ansible playbook

Reverse Proxy

I Showing haproxy.cfg.j2 jinja template file:

Haproxy.cfg.j2 template file

Step-3: For running the ansible playbook we can use the following command.

# ansible-playbook balancer.yml

Configure Webserver

Now Let us Running Reverse Proxy playbook.

Reverse Proxy

Here all tasks are done, so let’s crosscheck whether ansible has done the configuration or not

Checking IP of lb here status of haproxy is active. let us check the configuration file

SuccessFully Configured Haproxy

You can see over here that ansible added entry dynamically as we want so finally load balancer setup is done. let us check web group IP/ system

Successfully added two Entry

So Now our setup is done. let us check is it working or not?

Successfully done this Setup and working great

GitHub: https://github.com/Abdheshkumar691/loadbalancer.git

Linkdn: https://www.linkedin.com/in/abdhesh-kumar-656b73179/

Thanks for reading… If any questions please feel free to leave a comment below and Do connect with me on these platforms.

ARTH Learner at ARTH — The School of Technologies| Red Hat Certified System Administrator | Red Hat Certified Engineer | DevOps | AWS | Ansible | Docker |