Laodbalancer(HAProxy) using ANSIBLE ROLES
So Hey guys here I came up with another interesting task.
Today I am going to configure the laodbalancer using ansible but with the help of role so first let me tell you what is ansible and ansible roles
What is Ansible ?
Ansible is a software tool that provides simple but powerful automation for cross-platform computer support. It is primarily intended for IT professionals, who use it for application deployment, updates on workstations and servers, cloud provisioning, configuration management, intra-service orchestration, and nearly anything a systems administrator does on a weekly or daily basis. Ansible doesn't depend on agent software and has no additional security infrastructure, so it's easy to deploy.
What is Ansible roles?
Roles provide a framework for fully independent, or interdependent collections of variables, tasks, files, templates, and modules.
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. The breaking of playbook allows you to logically break the playbook into reusable components.
So now lets begin for task..
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.
So lets dive it.
Step 1:- Lets create a Instance using AWS for laodbalancer and apache server.
Step 2:- Lets create inventory file for ansible here
172.31.42.232 ->works as laodbalancer
172.31.39.201 -> web1 172.31.33.24 -> web2
Step 3:- Lets check whether or nodes are able to ping or not using command
# ansible all -m ping
Yes its working fine lets move on..
Step 4:- Lets create configuration file here we are using aws so we need to provide private key path and that file should be their in your control node.
Step 5:- Now Lets create a Roles by which we can easily maintain our code to create role we use command
# ansible-galaxy role init (role name)
After creating roles just update the path in configuration file so we can access roles from any where.
Step 6:- Lets check whether our roles are created or not using command
# ansible-galaxy roles list
As you can see it is created
Step 7:- Now lets write a code/playbook/tasks for load balancer using roles
Step 8:- Now lets write task/playbook/code for apache server using roles
while creating this we need to provide a code for checking here I am using php code which is their in my folder
<pre> <?php print `/usr/sbin/ifconfig` ?> </pre>
you can refer this also.
Step 9:- As we are creating load balancer we need to configure HAProxy file for dynamic ip creation or allocation
# /etc/haproxy/harpoxy.cfg
Note:- while running the main playbook you may face the problem of HAProxy file you will get error for this upload the HAProxy.cfg file from local computer so it works fine .
Step 10:- Lets create the main playbook from were are going to run or ansible playbook
Step 11:- Now its time to run and check whether our code is working or not using command
# ansible-playbook (playbook name).yml
Step 12:- lets check whether the service is working or not in your laodbalancer instance using command
systemctl status haproxy
Step 13:- lets check our HAProxy.cfg file whether the ip is loaded or not
yes its is their
Step 14:- lets check in Apache server also
# systemctl status httpd
Web1:-172.31.39.201
Web2:-172.31.33.24
Step 15 :- lets check whether our load balancer is working or not using webUI
http://<IP of loadbalancer>:8080/<page name>
So you can see it working correct .
It means our whole process is correct.