ARTH — Task 15 👨🏻‍💻

Task Description📄

🔅Create an ansible role myapache to configure Httpd WebServer.

🔅Create another ansible role myloadbalancer to configure HAProxy LB.

🔅We need to combine both of these roles controlling webserver versions
and solving challenge for host ip’s addition dynamically over each Managed Node in HAProxy.cfg file.

Roles provide a framework for fully independent, or interdependent collections of variables, tasks, files, templates, and modules. In Ansible, the role is the primary mechanism for breaking a playbook into multiple files. This simplifies writing complex playbooks, and it makes them easier to reuse.

Now Let’s start the Task :

In my case i created a file name with inventory.txt.

command : vim file_name.txt

In Inventory file write IP of the load balancer and Web Server…

Noe we need to create two roles one for the haproxy and another is for web server.

Syntax : ansible-galaxy role init role_name

Command : ansible-galaxy role init loadbalancer
Command : ansible-galaxy role init webserver

4. Update the Configuration file of ansible :

Now we need to update the conf file of ansible by giving the path of the role that we created..

Command : ansible-galaxy role list

Command : ansible all -m ping

First we need to go inside the loadbalancer role folder. Use : cd /root/ws2/loadbalancer . Then go inside the tasks folder Use : cd tasks . One file with name main.yml is already present their we need to write the code.

First we need to go inside the webserver role folder. Use : cd /root/ws2/webserver . Then go inside the tasks folder Use : cd tasks . One file with name main.yml is already present their we need to write the code.

Now we need to create a yml file with any name and write the code to combine both roles. In my case i have a folder named as final inside that i have final.yml file having this code..

Command : ansible-playbook file_name.yml

Check the connectivity using load balancer IP that they successfully done proxy or not..

In mycase load balancer IP- 192.168.43.64

URL- 192.168.43.64:8080/bag.php

Task Completed !!

Thanks for reading !!!