INTEGRATED ANSIBLE ROLES WITH WEBSERVER AND HAPROXY

shristi sharma
3 min readMar 27, 2021

Detail 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

Ansible is all about automation and we are deploying and executing our code. We put a playbook in one box and we deployed that box. That box is called roles.

Roles are useful in management purposes as it managed our code

Steps for Creating a Role👉

✔USE THIS COMMAND TO CREATE A ROLE

ansible-galaxy role init myapache

ansible-galaxy role init mylb

PART1

First We Will Create one Workspace

I name my workspace ws7 inside this created two roles named as

  • myapache (To configure webserver)
  • mylb (To configure loadbalancer)

Now we have to set our roles path into the ansible configuration file.

vim /etc/ansible/ansible.cfg

As we can see our both roles has been created

Then Go inside myapacheweb we can do ls to see the whole list inside the roles

Go inside tasks files open main.yml file👉

MAIN PLAYBOOK👉

Write ansible playbook for configuring WebServer

Lets see the vars file here we Initialize the variable that we want to use in the main playbook.

Lets Run The Playbook👇

RESULTS🎉

Webserver is Configured Successfully!!

PART2

Repeat the same steps as you done to create webserver

Now Create playbook for Loadbalancer

Lets check the Templates file

Now come to final step:

To run our roles we have to create create a directory , inside it i have created a file setup.yml in which i created a playbook which will run my roles.

Final Step

Run the playbook🎉

Thankyou for reading my blog😃

BY: SHRISTI SHARMA☺

--

--

shristi sharma

Aspiring Devops Enthusiastic |Content Creator |Python | Machine Learning | Cloud Computing