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 .
192.168.0.113 in this controller node we will config our Loadbalancer.
192.168.0.118 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 webserver_role
👉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 (192.168.0.118) :
systemctl status httpd
Now go to the Chrome and see webpage :
👉Here LB ip was (192.168.0.113) :
Thank for reading ….