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

How to play sounds effects in unity

Upgrade AWS EC2 Ubuntu 18.10 to 20.04

S Programming language

Integrating Explainability in Angular applications

An Overview of Asymptotic Notation

🤙Deploy Object Detection In 1 Min 🤙

C# tutorial — Guess the number game

ANU #105 — Bonus Levels & E-Skills

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

Configuration Of Multi Node K8S Cluster Over AWS Using Ansible

A school management app built using Golang and OOP

Custom Kubernetes Deployment Template Using Monokle.

Use EFS as a storage for multiple ec2 instances