Created ansible role to configure HAProxy LB.

Nityachawda
3 min readApr 17, 2021

Description:

  • Create an ansible role to configure Httpd WebServer.
  • Create another ansible role to configure HAProxy LB.
  • combine both of these roles.

Configuring HTTPD webserver:

Firstly we will create a role for httpd.

If we create a role we also have to update the ansible configuration file about the path of the role.

vim /etc/ansible/ansible.cfg

Inside this file we have to give the path.

roles_path = your role path

Now we will create role using the following command.

Then we will go inside our role and then go inside tasks folder and inside that we have main.yml file where we will write our code.

To run our code we will write a playbook.

Running the playbook.

Now let’s check our webpage .

Creating ansible role for HAPROXY LB :

we will create a role for HAPROXY.

role for webserver we have already created above.

Now, we will write our code inside main.yml file inside tasks folder inside the role we have created.

This is the code written inside webserver role.

In haproxy.cfg we have to make few changes . so, that it will take ip on its own . we don’t have to manually go and update the ip’s.

Now , we will create our playbook.

Running the playbook.

Again let’s check our webpage.

Thank You!!!

--

--