Configuration of Load balancer HAPROXY Using Ansible
Ansible Task-3
Deploy a Load Balancer and multiple Web servers on AWS instances using Ansible. 1.Provision of EC2 instances. 2.Retrieve the IP Address of instances Dynamically. 3.Configure web servers 4.Configure Load Balancer with web servers IP addresses.
In this task we are gonna configure Load Balancer HAPROXY on AWS using Ansible.
1.Provision of EC2 instances:
In this we will launch ec2 instances i.e. three for server configuration and one for load balancer configuration. lets write playbook for provision of EC2 instances before that we should write access key ID and secret access key of AWS account in one file. we should encrypt that file using ansible-vault encrypt --vault-id aws@prompt filename. after that
write playbook like
Run this playbook ansible-playbook --vault-id aws@prompt provision.yml
2.Retrieve the IP Address of instances Dynamically.
To retrieve IP of running instances of AWS using ec2.py. make ec2.py executable. export export AWS_ACCESS_KEY_ID=' ' export AWS_SECRET_ACCESS_KEY=' ' after that run ansible all --list-hosts or ansible all - m ping
after that update inventory file like below:
3.Configure web servers
To configure web servers first we need to write role using ansible-galaxy init server then write a task like
4.Configure Load Balancer with web servers IP addresses.
To configure HAPROXY on AWS write one more role ansible-galaxy init loadbal after that write playbook like
Here we need to update IP of web servers in haproxy.cfg To do that we need to do write code to update IP of server and port number. like
After that completing above steps write launch.yml file to run roles like
Run this command
# ansible-playbook launch.yml
After that write load balancer socket address means(IP+ port) then result will be
Thanks for reading.