Skip to main content

Command Palette

Search for a command to run...

Provision Haproxy on AWS using Ansible

Published
2 min read
Provision Haproxy on AWS using Ansible
S

I am a learner who likes to get behind the new technologies of the world and integrate them for a more efficient workflow. Currently learning AWS, GitOps, Kubernetes, and much more...

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 ....!!

25 views

More from this blog

Written Wisdom

35 posts

I'm a 22-year-old boy with a passion to learn about the DevOps Landscape. I love to explore things and deep dive into how these little pieces of code come together to form such state-of-the-art tools.