Configuring LoadBalancer using haproxy on AWS Using Ansible

Configuring LoadBalancer using haproxy on AWS Using 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 -

For launching Instance on AWS Cloud from localhost, we have to install library for ansible to contact with AWS EC2 instance.

For this install boto library using pip3 command …

pip3 install boto
pip3 install boto3

Here I create two playbook -

for launching AWS intance (web.yml)

No alt text provided for this image

for configuring webserver & configuring LoadBalancer using Haproxy (set.yml) .

No alt text provided for this image


Here I created three different role for launching instance , configuring webserver & configuring LoadBalancer using Haproxy.

No alt text provided for this image


To retrieve the public IP of the instance Dynamically we have to create dynamic inventory .

For this we have to download two files from this two links .

Run the below command to download those two files . These are the scripts given redhat officially .

Make a diff. folder and then enter these URL's to download scripts.

wget https://raw.githubusercontent.com/ansible/ansible/stable-2.9/contrib/inventory/ec2.ini

wget https://raw.githubusercontent.com/ansible/ansible/stable-2.9/contrib/inventory/ec2.py

Make both files executable by running this commands ...

chmod +x ec2.py
chmod +x ec2.ini

And then provide the AWS_REGION , AWS_ACCESS_KEY_ID andAWS_SECRET_ACCESS_KEY in the ec2.ini files

export AWS_REGION='ap-south-1'

export AWS_ACCESS_KEY_ID='enter your access key'

export AWS_SECRET_ACCESS_KEY='enter your secret key'


Now we have to edit inside ec2.py file. This file written in python 2 but we are using python 3 so we need to edit the header.

#!/usr/bin/python3

Setting up the Ansible configuration file as per requirement .

No alt text provided for this image

Now run the playbook to launch instance on AWS -

ansible-playbook web.yml

No alt text provided for this image
No alt text provided for this image
No alt text provided for this image

Here I launch 2 instances with tag name webserver for webserver and 1 instance with tag name loadbalancer for loadbalancer.

Our AWS instances launched -

No alt text provided for this image

Dynamic inventory Dynamically Retrieve the public IP of the instance .

Listing all the instance IP using ansible command ..

ansible all --list-hosts

No alt text provided for this image


To configure the HAProxy and webserver on the instance run another ansible playbook .

ansible-playbook set.yml

No alt text provided for this image
No alt text provided for this image

Now enter the public IP of the Loadbalancer Instance -

Our output -

No alt text provided for this image
No alt text provided for this image

Github url- https://github.com/NikhilSuryawanshi/Ansible_code/tree/main/task3

TASK COMPLETED!!!!

ThankYou For Reading .

要查看或添加评论,请登录

Nikhil Suryawanshi的更多文章

  • Neural Network & its Use Cases.

    Neural Network & its Use Cases.

    What are Neural Networks? Neural networks are a set of algorithms, they are designed to mimic the human brain, that is…

  • Ansible & NASA

    Ansible & NASA

    What Is Ansible? Ansible is an open source IT Configuration Management, Deployment & Orchestration tool. It aims to…

  • Artificial Intelligence & Machine Learning .

    Artificial Intelligence & Machine Learning .

    What is artificial intelligence? In computer science, the term artificial intelligence (AI) refers to any human-like…

  • Kubernetes Solving Usecases in Industries

    Kubernetes Solving Usecases in Industries

    What is Kubernetes? “Kubernetes, or k8s, is an open source platform that automates Linux container operations. .

  • Configuring Web Server 0n Docker Container Using Ansible .

    Configuring Web Server 0n Docker Container Using Ansible .

    Task Description?? ??Write an Ansible PlayBook that does the following operations in the managed nodes: ?? Configure…

    1 条评论
  • Increasing Storage Dynamically Using LVM .

    Increasing Storage Dynamically Using LVM .

    Attaching New/Extra Hard Disk to our Data Node - Here I created Two Hard Disk Of Size 10 & 12 Gb . Now Both volumes…

    1 条评论
  • ?? Create High Availability Architecture with AWS CLI ??

    ?? Create High Availability Architecture with AWS CLI ??

    ??The architecture includes- - Webserver configured on EC2 Instance - Document Root(/var/www/html) made persistent by…

  • Contributing Limited Amount of Data-Node Storage to Hadoop Cluster.

    Contributing Limited Amount of Data-Node Storage to Hadoop Cluster.

    Task 4.1 Description :- ??In a Hadoop cluster, find how to contribute limited/specific amount of storage as slave to…

  • Configure Web Server on AWS Cloud using ANSIBLE

    Configure Web Server on AWS Cloud using ANSIBLE

    Task description- Deploy Web Server on AWS using ANSIBLE ? Provision EC2 instance through ansible. ? Retrieve the IP…

社区洞察

其他会员也浏览了