🎇ANSIBLE ROLES !

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 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

To begin task following things must be done

※ Inventory file

you need to create two group one for the load balancer and other for the webservers here iam using local vms you can also use aws instances for web servers

※ ANSIBLE COINFIGURATION FILE

So now lets begin the task

STEP 1:-

change your directory to “ /root/.ansible/roles”

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

here we gonna write roles for both webserver and loadbalancer

Roles for My_Webserver

A. For TASK file:-

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

A. For TASK file:-

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

now we gonna create a playbook which will combine both the roles for controlling webserver versions and solving challenge for host ip’s addition dynamically over each Managed Node in HAProxy.cfg file.

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

play book executed succesfully!

STEP 4 :- Now lets see the result

♦️ In Haproxy Configuration File we can see that ip’s are added dynamically over managed nodes ;

※ lets check the result in browser

in the browser type

>>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