Provisioning HAProxy LoadBalancer and Webservers On AWS Using Ansible

Statement: Deploy a Load Balancer and multiple Web Servers on AWS instances through ANSIBLE!

🔅Provision EC2 instances through ansible.
🔅 Retrieve the IP Address of instances using the dynamic inventory concept.
🔅Configure the web servers through the ansible role.
🔅Configure the load balancer through the ansible role.
🔅The target nodes of the load balancer should auto-update as per the status of web servers.

Note: For Better Understanding Do read my previous post on Ansible

What is HAProxy ?

HAProxy is free, open source software that provides a high availability load balancer and proxy server for TCP and HTTP-based applications that spreads requests across multiple servers. It is written in and has a reputation for being fast and efficient (in terms of processor and memory usage). HAProxy is used by a number of high-profile websites including GoDaddy, GitHub, Bitbucket, Stack Overflow, Reddit, Slack,, Tumblr, Twitter and Tuenti and is used in the OpsWorks product from Amazon Web Services.

Step1: Create Ansible Playbook for webservers and load balancer.


Step2: On Local system,edit HAProxy config file.


Step3: Save the Playbook and Execute it.

Command to execute Playbook:# ansible-playbook <YML-File>
  1. Playbook for Webserver:
webserver playbook

2. Playbook for Proxy server

HAProxy Node
Check the IP Address

So our playbook successfully run

Lets take a look at EC2 Dashboard of AWS

ec2 dashboard

Thanks You For Reading :)




Love podcasts or audiobooks? Learn on the go with our new app.

Recommended from Medium

Git: local, remote, log ranges, and a script to sync

Learning by Playing: How to Learn Java With Coding Games and Quests?

Auto-Scaling Build Agents for GoCD

Which Bootcamp Is Best for You?

What is Redis and why with Use case?

I’m so excited to introduce you guys to Taye Marsel a biz owner from Burbank, CA!

7 Powerful Ways To Get Feedback From Users (And Fight Zombie Scrum!)

SUSTAINABLE SYSTEMS: Operational Choices in Sustainable Architecture

SUSTAINABLE SYSTEMS: Operational Choices in Sustainable Architecture by Anne Currie, illustration

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store
Prajwal Patil

Prajwal Patil

More from Medium

Elasticity in the Storage of distributed Hadoop Cluster

Why Cluster API is Ideal for Providing Consistent Kubernetes Experience Across Clouds

Actuator and Custom Indicator in Spring Boot

Beat Saber and Surgical Training?