ARTH — Task 15 👨🏻💻
Task 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.
Role for Configuring HTTPD
Role: In Ansible, the role is the primary mechanism for breaking a playbook into multiple files. This simplifies writing complex playbooks, and it makes them easier to reuse.
in this article my managed node is 127.0.0.1 :
Creating the role in Controller node and setup Path in Inventory File :
Here i create the my_http_role under the roles folder :
Setup roles Path :
🔹Creating an ansible role my_http_role:
# ansible-galaxy role init my_http_role
🔹For see how many role in your pc :
# ansible-galaxy role list
🔹For configuring server using my_http_role:
🔹Put Task in Main.yml file :
🌟Now run main yml file http_role.yml :
🔹Let’s check our webpage from the browser :
Successfully Run ….
Ansible role myloadbalancer to configure HAProxy LB.
Roles:
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🌟
192.168.0.113 in this controller node we will config our Loadbalancer.
🌟Managed Node🌟
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 ….