ARTH — Task 15 👨🏻💻
🔅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.
What is Roles ??
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 :
1. Create Inventory file with any name :
In my case i created a file name with inventory.txt.
command : vim file_name.txt
2. Update the Inventory File :-
In Inventory file write IP of the load balancer and Web Server…
3. Creating Roles :
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..
5. Check the role path is successfully updated or not :
Command : ansible-galaxy role list
6. Check the connectivity with the node :
Command : ansible all -m ping
7. Code for configure HAProxy :
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.
loadbalancer yml code :
8. Code for configure Webserver:
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.
webserver yml code :
9. Make HAProxy configuration file dynamic :
10. Combine both of these roles :
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..
11. Now run the above yml file :
Command : ansible-playbook file_name.yml
12. Check Configuration file of HAProxy in managed node updated dynamically or not :
13. Check Connectivity in the browser :
Check the connectivity using load balancer IP that they successfully done proxy or not..
In mycase load balancer IP- 192.168.43.64
Task Completed !!
Thanks for reading !!!