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.
After the that download the ec2.py ans ec2.ini file for creating inventory in the /root/aws.
after that export the "export EC2_INI_PATH"
"export AWS_ACCESS_KEY_ID"
"export AWS_SECRET_ACCESS_KEY"
After that for checking its working or not check ansible all --list-hosts.
here my inventory is set.
3)launching the aws instance:for launching instance i write one playbook.
and than run this command for playbook ansible-playbook "filename"
here i launching the instance on aws.
after that checking for host
its showing launching instance ip .we done thise
4)After that i create on inventory for the web ,lb
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.
<> for web server <>
task :
<> for lb<>
task:
handler:
after that i change in my haproxy.cfg file.
6)creation of playbook for all lb ,web:
After the creating the playbook run thise.
Done ✔.
After thise lets check :
first search:
second serach:
Excelente!!! It works fine!!🥳🥳
Our Task Completed Successfully!!!🎯
Thank you Mr. Vimal Daga Sir for this great task and immense guidance.
Keep going buddy!!