Configuring Web Server and Load Balancer using Ansible Roles…

Arjun Nigam
4 min readDec 28, 2020

Hey guys, I am back with another interesting task where I am gonna configure httpd Web Server and HAProxy Load Balancer using Ansible roles also

We will combine both of these roles controlling web server versions and solve the challenge for host IP’s addition dynamically over each Managed Node in HAProxy.cfg file.

So let’s get started

As you can observe in the image below, i have created two roles for this task.

myapache — for web server

And myloadbalancer — for loadbalancer

Command used: ansible-galaxy role init role_name

As you can see two folders of the created roles have appeared in the directory.

Note :

Add the path to your roles in the Ansible config file to let Ansible know the path to your roles. The image below is of my Ansible config file where I have specified my roles path.

Also, I have configured the roles with the required info of the tasks , webpage files, handlers, etc.

As you can observe in the image below, this is my main playbook where I have associated the roles with their respective hosts.

The link to this playbook and my roles folder which I have configured is given at the end.

Now before running the playbook let’s check if we are connected to our respective hosts or not.

And as you can observe in the image below, we are connected.

Now that we are connected, it’s time to run our Playbook.

And as you can observe in the image below, it ran successfully.

Now , it’s time to check our web server. For that we are gonna need the public IP of our load balancer.

Now that we have the IP and let’s run the webpage.

And as you can observe in the image below it’s working perfectly.

Now , let’s add another backend Server to it.

Let’s check connectivity with the hosts.

And as you can observe in the image below all three hosts , along with the new host (for backend server) are connected perfectly.

Let’s run the Playbook again for the new backend server.

And as you can observe in the image below, it ran successfully.

Now let’s check the webpage…

And as you can observe in the image below, It is running perfectly!!!

That is how you Configure Web Server and Load Balancer using Ansible Roles…

That was all from my side. Hope you found this interesting, I will be back with some other interesting practicals.

Till then, keep learning :)

View the Playbook used on Github:

https://github.com/Arjun0071/rolesconfig_web_lb

Arjun Nigam

https://www.linkedin.com/in/arjun-nigam-4728b11b8

Signing Off!!!

--

--