Arth2020 task12

Arth2020 task12

This article is to explain how to configure a highly automated setup for Reverse proxy i.e Haproxy and update it's configuration file automatically and all the operating system launch on the top of AWS cloud and fetch all the IPs dynamically using ansible dynamic inventory.

Task Description

  • 12.1 Use Ansible playbook to Configure Reverse Proxy i.e. Haproxy and update it's configuration file automatically on each time new Managed node (Configured With Apache Webserver) join the inventory.
  • 12.2 Configure the same setup as 12.1 over AWS using instance over there.

Introduction

Server automation now plays an essential role in systems administration, due to the disposable nature of modern application environments. Configuration Management tools such as Ansible are typically used to streamline the process of automating server setup by establishing standard procedures for new servers while also reducing human error associated with manual setups.

Ansible offers a simple architecture that doesn’t require special software to be installed on nodes. It also provides a robust set of features and built-in modules which facilitate writing automation scripts.

Ansible dynamic inventory

The dynamic inventory script can do anything to get the data (call an external API, pull information from a database or file, etc.), and Ansible will use it as an inventory source as long as it returns a JSON structure like the one above when the script is called with the --list.

Prerequisites

In order to execute the automated setup provided by the playbook we’re discussing in this article, you’ll need:

  • One Ansible control node: an Red Hat 8 machine with Ansible installed and configured to connect to your Ansible hosts using SSH keys. Make sure the control node has a regular user with sudo permissions and a firewall enabled.
  • One or more Ansible Hosts: one or more remote Red Hat 8 servers previously set up, these will be work as a managed node.

First configure the ansible dynamic inventory so that we can fetch IPs dynamically. and then launch all the operating system over cloud then third and setup load balancer through haproxy. and my all the files and folder related to this task is in /ansible/arthtask12.2/ folder.

DYNAMIC INVENTORY SETUP

Here you will learn how to set up a dynamic inventory on AWS using boto , ec2.yml and ec2.ini file.

Follow the steps carefully for the setup.

Step 1: 

  • Install python3 "$ yum install python3 -y"
  • Install the boto3 and boto library "$ pip3 install boto3" , "$ pip3 install boto"

step2:

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



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


No alt text provided for this image
  • make the ec2.py file executable using "$ chmod +x ec2.py"
  • open ec2.py file and change env python to python3 in the first line of this file because this python code is written in python2 and now we are using python3 so we need to change it.
No alt text provided for this image

step3:

  • set environment variable for authentication .
No alt text provided for this image
AWS_RGION: <YOUR-AWS-REGION-NAME-HERE>
AWS_ACCESS_KEY_ID: <YOUR-AWS-ACCESS-KEY-HERE>
AWS_SECRET_ACCESS_KEY: <YOUR-AWS-SECRET-KEY-HERE>


  • update this /ansible/arthtask12.2/mydb directory in ansible configuration file and also set aws private_key and user through which you wanted to launch os on aws.
No alt text provided for this image
  • note:- go to that folder where your private key is there and run "$ chmod 400 <private_key_name"
No alt text provided for this image

dynamic inventory configuration is done now u can check using using "$ ansible all --list-hosts"

No alt text provided for this image

LAUNCH AWS OPERATING SYSTEM USING ANSIBLE PLAYBOOK

I need three operating system one for haproxy configuration and other two for webserver configuration.

Below is the ansible playbook code for ec2 instances name as play.yml .

vim  /ansible/arthtask12.2/play.yml

as we are launching OS so we don't have any IP now , and to use ansible playbook or ad-hock command we need IP as host. so we will use localhost.

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

while launching ec2 instances we need to give aws-access-key and aws-secret-key which is very critical for us. so, we create a file and set all the variable value in this file

vim   /ansible/arthtask12.2/var.yml

      aws_access:  xxxxxxxx
      aws_secret:  xxxxxxxxxxxxxxxxxxxxxx
      region: ap-south-1

here giving instance - tags is important , we will use it in configuration of haproxy file dynamically.

How to Use this Playbook

The playbook file, containing the tasks to be executed on the remote server.

Run command "ansible-playbook <play book name>" to run this playbook.

No alt text provided for this image

now try to ping using "$ ansible all -m ping "

No alt text provided for this image

as we have configure dynamic inventory so we don't need to write the IPs of all the operating system in inventory file. dynamic inventory will fetch all the details dynamically.

we can list all the details about all the os using "$ ./ec2.py --list".

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

we will use these two tag.

operating system setup is done.

CONFIGRATION REVERSE PROXY (WITH APACHE WEBSERVER)

First install haproxy software in your ansible manage node

yum install haproxy -y

No alt text provided for this image

now got to the /etc/haproxy and copy haproxy.cfg in your main task folder /ansible/arthtask12.2

No alt text provided for this image

now edit this haproxy.cfg file so that it can automatically update on each time new managed node.

No alt text provided for this image

now create one more ansible playbook name as main.yml . below is the code

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

here I am using that tags name which I have fetch using dynamic inventory

tag_name_loadbalancer   <I am using this host for haproxy configuration >
tag_name_web_server      < and this for apche webserver>
 

we can also check the syntax error using "$ ansible-playbook mail.yml --check"

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

Now run this playbook main.yml

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

everything is working good. now we can check load balancer is working or not.

we have configure haproxy in <tag_name_loadbalancer> and this contain load balancer IP which is 15.207.21.111

Now browse https://15.207.21.111:8080/ multiple time .

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

I have written PHP code to print the IP address of that system . if will browse multiple time https://15.207.21.111:8080/ it will give every time different IP , its means load balancer is working good.

Thank you for reading

Aman Kumar Abhishek

Student at ARTH - The School of Technologies

4 年

so impressive ??

Aman Kumar Abhishek

Student at ARTH - The School of Technologies

4 年

Thank you for sharing ?? Sulekha .

Satyam Kumar

DevOps Engineer at Celebal Technologies

4 年

First comment ??

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

Km Sulekha的更多文章

  • Docker GUI Task26

    Docker GUI Task26

    This article describe how we can launch GUI software on Docker. Task Description *GUI container* on the *Docker* Launch…

  • HotStar Case Study Task2

    HotStar Case Study Task2

    This article will describe the journey of Hotstar’s infrastructure from EC2 to Kubernetes. The journey about why, what,…

    1 条评论
  • Case Study of AWS SQS

    Case Study of AWS SQS

    In this article I am going to share what is Amazon SQS and industries use case of Amazon SQS. Amazon SQS Amazon Simple…

  • ARTH Task18

    ARTH Task18

    In this article we are going to explain how to we can configure WordPress on ec2 instances and connect this with Amazon…

  • Arth2020 Task17

    Arth2020 Task17

    In this article we are going to create chat program using python socket programming and Threading. Task Description…

    2 条评论
  • Create a setup so that you can ping google but not able to ping Facebook from same system Task13

    Create a setup so that you can ping google but not able to ping Facebook from same system Task13

    This article is to explain how we can create an interesting networking setup in which only we can reach to google but…

  • How big MNC's like Google , Amazon etc stores, manages and manipulate Thousands of Terabytpes of data with High Speed and High Efficiency Task-1

    How big MNC's like Google , Amazon etc stores, manages and manipulate Thousands of Terabytpes of data with High Speed and High Efficiency Task-1

    In a world where competition is intense, users will simply dump you, if your app slows down or freezes. So your…

  • Industries use case of AKS ?

    Industries use case of AKS ?

    Kubernetes is by far the most popular container orchestration tool, yet the complexities of managing the tool have led…

  • Ansible-Tower

    Ansible-Tower

    In this 3 hours of session we learn practical demo how industries are using Ansible-Tower and how it gives lots of…

  • How industries are solving challenges using Ansible

    How industries are solving challenges using Ansible

    Companies using Ansible We have data on 8,781 companies that use Ansible. The companies using Ansible are most often…

    2 条评论

社区洞察

其他会员也浏览了