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
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
Ansible Configuration File : /etc/ansible/ansible.cfg
Now we will configure precreated haproxy.cfg file So that we can copy it to the proxy server later :
index.html
ANSIBLE PLAYBOOK:
Host : load
Host : webserver
Now we will run ansible play book : load.yml
ansible-playbook load.yml
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.
AFTER REFRESH:
We see that our webserver IP has changed
Here we have successfully created our load balancer using ansible
Thank you!!!