Provision Haproxy on AWS using Ansible

Provision Haproxy on AWS using Ansible

Hi there! Today we are going to see how we can configure haproxy and webserver setup on EC2 instances. So let's get into it. I have already discussed briefly what is a load balancer and stuff. You can see it here.

Diagram_2.png

Let's start

So we will have a setup like this :

  • 2 Webservers with tag [ env: Webserver ]
  • 1 Load Balancer with tag [ env: Loadbalancer ]

Our playbook looks like this.

Screenshot (1044).png

You can see it here

I have also used different variable files to provide the required values to launch and configure the instance.

And I have used VAULT here to store my AWS credentials in an encrypted form so that it can't be accessed by anyone directly. You can see it here.

VirtualBox_Ansible Controller Redhat_06_01_2021_21_52_37.png

So now let's run our playbook using ansible-playbook --ask-vault-pass main.yml. Here --ask-vault-pass will ask the password to decrypt the vault and use those credentials in the playbook.

VirtualBox_Ansible Controller Redhat_06_01_2021_21_50_21.png

VirtualBox_Ansible Controller Redhat_06_01_2021_21_50_32.png

You can see our playbook ran successfully and now let's check AWS console.

Screenshot (1045).png

Screenshot (1046).png

Screenshot (1047).png

You can see it is configured and now let's see the results.

Screenshot (1048).png

Screenshot (1049).png

Yes, we can access the servers and load-balancing is happening too. So in this way, we can setup simple load balancer on AWS EC2 instance.

That's it for this one and see you again next time ....!!

Did you find this article valuable?

Support Written Wisdom by becoming a sponsor. Any amount is appreciated!