Setting up Load Balancer and Web Server using Ansible Roles

Saurabh Suthar
3 min readApr 26, 2021

--

LOAD BALANCER AND WEB SERVERS

Setup Description: In this article, we’re going to create a role and set up the Load Balancer and three Web Servers over the four systems using the Ansible Roles, we created.

Steps to achieve the above setup:

  • Initialize the ansible roles for the webserver and load balancer.
  • Add the playbooks for the tasks in the tasks folder.
  • Add templates in the templates folder.
  • Write the playbook for performing the tasks using roles.

Above screenshot shows the directory structure of the complete task.

Let’s start our practical by checking the systems are reachable or not using the following command.

ansible -m ping all
Ping all the Systems

All the systems are successfully pinged. Now, we can start writing our task for the Roles for the above-mentioned setup.

Firstly, we will create the roles using the following command.

ansible-galaxy init role_name

I’ve explained the setup of Load Balancer and Web Server in the above article. So, I’m adding the playbooks to the ansible roles.

Playbook for executing Roles

The additional playbook that we need to execute the roles.

Let’s execute the playbook: web.yml with the following command.

ansible-playbook -vv web.yml
Installing HTTP, PHP and copying files
Enabling Firewall and starting Web Server
Installing HAproxy, enabling firewall and start the HAproxy

All the tasks are executed successfully.

Accessing the website using the IP_address:port and three different screenshot shows the different system is accessed using the same IP address. This depicts the Load Balancer is working fine and the traffic is distributed over different web servers in a round-robin fashion.

Give a 👏 , if you liked reading it.

--

--

No responses yet