Deploying Load Balancer using HAProxy with Ansible Automation

aws — ansible — HAProxy

About the project

The main objective is to deploy a Load Balancer and multiple Web Servers on AWS instance through Ansible. The steps to be followed for accomplishing this are as follows:

· Provision ec2 instances through Ansible

· Retrieve the IP address of the instance using 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.

About Ansible

Ansible 2.9 is a software/tool that is used for configuration management. To launch a server on an OS, it needs to be configured which can be done in the following ways.

1. Manual method

2. Automatic method:

a. Traditional scripts: This includes Imperative Language where the developer needs to specify how a particular action is to be performed.

b. Intelligent scripts: This includes Declarative Language where the developer only needs to enter what is to be done and the coding is done internally by the script.

Ansible is based on python and is thus installed using the pip command. The system (OS) on which the code of ansible is run is called the controller node. All the other devices connected to the network are referred to as managed node.

About 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 the requests across multiple servers. It is written in C and has a reputation for being fast and efficient.

Procedure:

STEP 0:

Before you start off, it is important to have the following ready at your fingertips

AWS account

Ansible downloaded

ec2.py downloaded for the ansible documnetation

ansible-inventory set

STEP 1:

Creating an ansible playbook loadbalancer.yml which is run to deploy the web server and load balancer and acts as a one click mode of creating, launching an instance and downloading an starting the services.

ansible-playbook

STEP 2:

Creating ansible role launch which takes care of creating an ec2 instance with the image and the security group mentioned after logging into the console with the access key and security key. This sensitive information is in fact stored in a separate folder under the vars folder of the role or it may also be further protected in an ansible vault.

launch of ec2 instance

STEP 3:

Creating ansible role, loadbalancerserver, which launches and maintains the HAProxy load balancer. This is written in the tasks folder in the main.yml file.

STEP 4:

Creating ansible role, webservers, which creates and deploys a web page on the instance. This includes the file index.html.j2 which contains the code for the webpage. It waits for the load balancer to direct the client to the webpage and in case it is held, the service is restarted.

web server

STEP 5:

Go to your aws console, the ec2 instances with the tag names of LoadBalancer and Webserver are lanched and visiting the webpage at <ipaddress>:8080.

successfully completed.
aws console

Keep following for more such projects. Do drop a mail, with suggestions for improvement at abhiroop1.bas@gmail.com

--

--

--

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

Recommended from Medium

Software Business Models, Examples, Revenue Streams, and Characteristics for Products, Services…

Yolo-V4 Installation On Ubuntu 18.04

NO CODE TOOLS: What are they?

Fixing powerline in homebrew’s vim

Create Polymorphic or multiple entity lookup field in Microsoft Dynamics 365

The Architecture Journey — Adapting DDD from MVC

Time Boxing for Software Projects

Corda Spaceship Auction-Part 1 (Project Setup)

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
Abhiroop Bas

Abhiroop Bas

More from Medium

How to route domain names to containers running in EC2?

What is CI/CD? — A 30,000 foot view

CI/CD Overview

Step-by-step guide to create an autoscaled GitLab runner on AWS

Jfrog Artifactory integration with CI/CD Jenkins