HA Proxy configuration in AWS using Ansible

Yash Modi
5 min readMay 1, 2021


In my previous article, I have explained about the concepts of HA Proxy and Load Balancer and also configured HAProxy and Webserver with the help of ansible-playbook.

Now, In this article, I am going to show you how to configure the same HA Proxy Setup on the top of AWS Cloud.

But, before configuring the Load Balancer, let’s learn What is Cloud Computing and why AWS Cloud over other cloud service providers?

What is cloud computing?

Cloud computing is the on-demand delivery of IT resources over the Internet with pay-as-you-go pricing. Instead of buying, owning, and maintaining physical data centers and servers, you can access technology services, such as computing power, storage, and databases, on an as-needed basis from a cloud provider like Amazon Web Services (AWS).

Who is using cloud computing?

Organizations of every type, size, and industry are using the cloud for a wide variety of use cases, such as data backup, disaster recovery, email, virtual desktops, software development and testing, big data analytics, and customer-facing web applications. For example, healthcare companies are using the cloud to develop more personalized treatments for patients. Financial services companies are using the cloud to power real-time fraud detection and prevention. And video game makers are using the cloud to deliver online games to millions of players around the world.

Benefits of cloud computing



Cost savings,

Deploy globally in minutes, and many more…

Why AWS Cloud?

Amazon Web Services (AWS) is the world’s most comprehensive and broadly adopted cloud platform, offering over 200 fully featured services from data centers globally. Millions of customers — including the fastest-growing startups, largest enterprises, and leading government agencies — are using AWS to lower costs, become more agile, and innovate faster.

Features of AWS.

Most functionality

AWS has significantly more services, and more features within those services, than any other cloud provider–from infrastructure technologies like compute, storage, and databases–to emerging technologies, such as machine learning and artificial intelligence, data lakes and analytics, and Internet of Things.

This makes it faster, easier, and more cost effective to move your existing applications to the cloud and build nearly anything you can imagine.

Largest community of customers and partners

AWS has the largest and most dynamic community, with millions of active customers and tens of thousands of partners globally. Customers across virtually every industry and of every size, including startups, enterprises, and public sector organizations, are running every imaginable use case on AWS.

The AWS Partner Network (APN) includes thousands of systems integrators who specialize in AWS services and tens of thousands of independent software vendors (ISVs) who adapt their technology to work on AWS.

Most secure

AWS is architected to be the most flexible and secure cloud computing environment available today. Our core infrastructure is built to satisfy the security requirements for the military, global banks, and other high-sensitivity organizations.

This is backed by a deep set of cloud security tools, with 230 security, compliance, and governance services and features. AWS supports 90 security standards and compliance certifications, and all 117 AWS services that store customer data offer the ability to encrypt that data.

Now, since we got to know enough about the Cloud Computing and AWS, let’s start configuring the Load Balancer on the top of AWS CLoud.


In this current article, i an going to create an ansible-playbook that will automatically launch Instances in AWS Cloud and configure HA Proxy Setup on top of it. I will create a complete automated setup that will automatically update the inventory as soon as the instance is launched in AWS.

Let’s build the complete task step-by-step:-

First, let’s create an ansible-playbook that will launch instances in AWS Cloud:

Now, to provide aws_access_key and aws_secret_key, let’s create a file using

#ansible-vault create — vault-id prod@prompt secure.yml

Now, run this playbook and the aws instances will be launched automatically.

And, the Instances are launched successfully…

Now, since we have launched the instance, we need our ansible to update it’s inventory and for that, let’s use the python code that will automatically update the inventory and update it in the configuration file.

To download these two files:

wget https://raw.githubusercontent.com/ansible/ansible/stable-2.9/contrib/inventory/ec2.py

wget https://raw.githubusercontent.com/ansible/ansible/stable-2.9/contrib/inventory/ec2.ini

Now, let’s tell our ansible configuration file to update the inventory by running the following python code:

Now, whenever we launch instance, our inventory will be updated automatically…

Now, since our inventory is updated, let’s create an ansible-playbook to configure HA Proxy and WebServer in respective instances and launch our Application.

Now, run this playbook and the complete configuration will be done in AWS automatically.

And thus, all the objectives of the task is successfully completed.

Finally, we can connect to our website with the ip of Load Balancer at port 8080 (given by me in HA Proxy Configuration File)

The complete code of the task is uploaded in GitHub for your reference.

Hope you liked the article.

Thank you for reading this.

Have a Nice Day :)