Configuration of Load balancer HAPROXY Using Ansible

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

No alt text provided for this image

write playbook like

No alt text provided for this image
No alt text provided for this image

Run this playbook ansible-playbook --vault-id aws@prompt provision.yml

No alt text provided for this image

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

No alt text provided for this image
No alt text provided for this image

after that update inventory file like below:

No alt text provided for this image


3.Configure web servers

To configure web servers first we need to write role using ansible-galaxy init server then write a task like

No alt text provided for this image

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

No alt text provided for this image
No alt text provided for this image

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

No alt text provided for this image

After that completing above steps write launch.yml file to run roles like

No alt text provided for this image

Run this command

# ansible-playbook launch.yml

No alt text provided for this image
No alt text provided for this image

After that write load balancer socket address means(IP+ port) then result will be

No alt text provided for this image
No alt text provided for this image
No alt text provided for this image

Thanks for reading.



要查看或添加评论,请登录

Ganesh Chaudhari的更多文章

社区洞察

其他会员也浏览了