This repository contains an Ansible playbook designed to automatically configure an Nginx Load Balancer, distributing incoming HTTP requests evenly across five backend web servers.
The provided Ansible playbook handles:
- β Installation of Nginx on the designated load balancer host.
- β Automated Nginx configuration as a reverse-proxy load balancer.
- β Efficient load distribution among five backend servers.
nginx-loadbalancer-ansible/
βββ hosts # Inventory of servers
βββ loadbalancer.yml # Main Ansible playbook
βββ templates
βββ nginx_lb.conf.j2 # Nginx configuration template
Ensure the following prerequisites are met:
- Ansible installed on your local control machine:
sudo apt install ansible- SSH key-based authentication configured on all remote hosts.
- Ubuntu/Debian-based Linux servers for load balancer and backend hosts.
Update the hosts file to reflect your server IP addresses or domain names:
[loadbalancer]
lb.example.com ansible_host=192.168.1.10
[webservers]
web1.example.com ansible_host=192.168.1.21
web2.example.com ansible_host=192.168.1.22
web3.example.com ansible_host=192.168.1.23
web4.example.com ansible_host=192.168.1.24
web5.example.com ansible_host=192.168.1.25Run the following command to deploy the load balancer:
ansible-playbook -i hosts loadbalancer.ymlTest your load balancer by navigating to:
http://<loadbalancer-ip-address>/
You should see the load balancing in action across your backend servers.