Load balancing setup using haproxy.
on AWS WITH ANSIBLE.

Load balancing setup using haproxy. on AWS WITH ANSIBLE.

🔰Task Description:

♦️Launch an AWS instances with the help of ansible.

♦️Retrieve the public IP which is allocated to the launched instance.

♦️With the help of the retrieved Public IP configure the load balancing setup using haproxy.

Let’s start!!!

🔰 Before the starting the task lets gets some information about following points.

Ansible🤔

Ansible is an open-source software provisioning, configuration management, and application-deployment tool enabling infrastructure as code. It runs on many Unix-like systems, and can configure both Unix-like systems as well as Microsoft Windows. It includes its own declarative language to describe system configuration. Ansible was written by Michael DeHaan and acquired by Red Hat in 2015. Ansible is agentless, temporarily connecting remotely via SSH or Windows Remote Management (allowing remote PowerShell execution) to do its tasks.

AWS 😀

AWS is a cloud which is provided by Amazon. Amazon Elastic Compute Cloud (Amazon EC2 ) is a part of Amazon.com's cloud-computing platform, Amazon Web Services, that allows users to rent virtual computers on which to run their own computer applications. AWS EC2 service provisions resources like RAM , HardDisk . CPU etc.

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 C and has a reputation for being fast and efficient . HAProxy is package to balance load on the server. HAProxy server is a frontend for client . It distribute load between servers.

So let’s start our journey!!

1)First of all, Install boto software:

Boto is the Amazon Web Services (AWS) SDK for Python. It enables Python developers to create, configure, and manage AWS services, such as EC2 and S3. Boto provides an easy to use, object-oriented API, as well as low-level access to AWS services.

2)Dynamic Inventory:for the dynamic inventory i change in my ansible.cfg.

No alt text provided for this image

After the that download the ec2.py ans ec2.ini file for creating inventory in the /root/aws.

No alt text provided for this image

after that export the "export EC2_INI_PATH"

"export AWS_ACCESS_KEY_ID"

"export AWS_SECRET_ACCESS_KEY"

No alt text provided for this image

After that for checking its working or not check ansible all --list-hosts.

No alt text provided for this image

here my inventory is set.

3)launching the aws instance:for launching instance i write one playbook.

No alt text provided for this image

and than run this command for playbook ansible-playbook "filename"

No alt text provided for this image

here i launching the instance on aws.

No alt text provided for this image

after that checking for host

No alt text provided for this image

its showing launching instance ip .we done thise

4)After that i create on inventory for the web ,lb

No alt text provided for this image

after that for getting ip of instance i edit in my /bhost.txt

5)creation of roles:

for the creation of roles .use thise command ansible-galaxy init "yourrolename". so i created two roles one for webserver and one of loadbalancer. and don't forgot to give your role path in inventory.

No alt text provided for this image

<> for web server <>

task :

No alt text provided for this image

<> for lb<>

task:

No alt text provided for this image

handler:

No alt text provided for this image

after that i change in my haproxy.cfg file.

No alt text provided for this image

6)creation of playbook for all lb ,web:

No alt text provided for this image

After the creating the playbook run thise.

No alt text provided for this image

Done ✔.

After thise lets check :

first search:

No alt text provided for this image

second serach:

No alt text provided for this image


Excelente!!! It works fine!!🥳🥳

Our Task Completed Successfully!!!🎯


Thank you Mr. Vimal Daga Sir for this great task and immense guidance.


Thank you for reading article upto end😄






To view or add a comment, sign in

More articles by Hitesh Bendale

  • Google cloud (GCP)

    <>Task Description<> 1. Create multi projects 2.

    5 Comments
  • Deploy Web Server on AWS through ANSIBLE!

    <>Task Description<> >Launch an AWS instance with the help of ansible. >Retrieve the public IP which is allocated to…

    5 Comments
  • Integrating Ansible and Docker.

    What is Ansible? Ansible is a configuration management system written in Python using a declarative markup language to…

    2 Comments
  • Simple Video And Audio App Using Flutter

    Flutter:Flutter is Google’s UI toolkit for building beautiful, natively compiled applications for mobile, web, and…

    3 Comments

Others also viewed

Explore content categories