🎇ANSIBLE ROLES !

ARTH TASK 15 :-

đź”…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 ANSIBLE ?

Ansible is a radically simple IT automation engine that automates cloud provisioning, configuration management, application deployment, intra-service orchestration, and many other IT needs.

WHAT IS ANSIBLE ROLES ?

Ansible role is a set of tasks to configure a host to serve a certain purpose like configuring a service. Roles are defined using YAML files with a predefined directory structure. A role directory structure contains directories: defaults, vars, tasks, files, templates, meta, handlers.

so lets begin the task:-

-> PREREQUESITES

※ Inventory file

※ ANSIBLE COINFIGURATION FILE

So now lets begin the task

STEP 1:-

Create an ansible role “My_Webserver” to configure httpd WebServer and another ansible role “myloadbalancer” to configure HAProxy LB.

command

>> ansible-galaxy role init My_Webserver

>> ansible-galaxy role init My_Loadbalancer

To check whether the roles are created or not use command

>> ansible-galaxy role list — roles-path /root/.ansible.roles

STEP 2 :- Writing Roles

※ Roles for My_Webserver

open the file main.yml inside task file and write the following code

B. For VARS file:-

open the file main.yml inside vars file and write the following code

C. For HANDLERS file:-

open the file main.yml inside handlers file and write the following code

D. For files:-

open the file and create a .php file index.php and write the following code

※ Roles for My_LoadBalancer

open the file main.yml inside task file and write the following code

B. For VARS file:-

open the file main.yml inside vars file and write the following code

C. For HANDLERS file:-

open the file main.yml inside handlers file and write the following code

D. For files:-

HAPROXY CONFIG FILE

STEP 3 :- Combing roles together

STEP 4 :- Lets run our playbook final-setup.yml

play book executed succesfully!

STEP 4 :- Now lets see the result

※ lets check the result in browser

>>http://<loadbalancer_ip>:<port_no>/<web_page>.html

after browsing my loadbalancer its connecting to ip of device 1

and after refreshing it goes to ip of second device

Hence the Task is Completed !!!

Thanks Vimal Daga sir for mentoring us every students wants mentor like you ,feeling blessed to be part of arth and i am eagerly waiting for more such tasks

Thanks for Reading!!!

--

--

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store