Configure Reverse Proxy Using Ansible

Configure Reverse Proxy Using Ansible

First, let’s understand what is a load balancer?

A load balancer does the work of 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.

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

My Workspace Where I have kept the inventory file, playbook and private key file: /loadbalance

No alt text provided for this image

Inventory File:

Proxy server IP: virtual machine : 192.168.43.238

Webserver IP:

  • virtual machine : 192.168.43.131
  • aws-ec2-instance : public IP==>13.127.228.92

private IP==>172.31.1.222

No alt text provided for this image

Ansible Configuration File : /etc/ansible/ansible.cfg

No alt text provided for this image


Now we will configure precreated haproxy.cfg file So that we can copy it to the proxy server later :

No alt text provided for this image

index.html

No alt text provided for this image

ANSIBLE PLAYBOOK:

Host : load

No alt text provided for this image

Host : webserver

No alt text provided for this image

Now we will run ansible play book : load.yml

ansible-playbook load.yml
No alt text provided for this image
No alt text provided for this image

After running the playbook using the above command our setup will be ready. Now we will access the IP of the load-balancer at port 8080 and will refresh to see that after every refresh we get connected to a different back end web server every time thus maintaining the load balancing.

No alt text provided for this image

AFTER REFRESH:

No alt text provided for this image

We see that our webserver IP has changed

Here we have successfully created our load balancer using ansible

Thank you!!!

To view or add a comment, sign in

More articles by Sagar Sharma

Others also viewed

Explore content categories