Create another ansible role myloadbalancer to configure HAProxy LB.

Mihir Patel
3 min readJan 6, 2021


Roles let you automatically load related vars_files, tasks, handlers, and other Ansible artifacts based on a known file structure. Once you group your content in roles, you can easily reuse them and share them with other users

In this article we create two Role for Haproxy and Webserver configure .

🌟Controller Node🌟 in this controller node we will config our Loadbalancer.

🌟Managed Node🌟 this managed node is our backed webserver .

👉 Creating an ansible role haproxy_role and webserver_role:

# ansible-galaxy role init haproxy_role
# ansible-galaxy role init

👉For see how many role in your machine :

# ansible-galaxy role list

Configure Role path in Inventory :

My Roles in Role folder so role_path=/root/roles

👉For configuring Load Balancer using haproxy_role role:

update the man.yml file in haproxy_role .

In haproxy.cfg use jinja code like below .

👉For configuring webserver using webserver_role role:

upadte the main.yml file in webserver_role .

👉create the main haproxy_role.yml File :

# ansible-playbook haproxy_role.yml

Now run this haproxy_role.yml file :

👉Now see the Backedwebserver Status ( :

systemctl status httpd

Now go to the Chrome and see webpage :

👉Here LB ip was ( :

Thank for reading ….