Configuring Reverse Proxy & Setup AWS instance
Tags: Redhat Linux, Ansible, Haproxy, Aws Ec2, Reverse Proxy

Hey!! Learner this article content that have to create Ansible Playbook i.e. Launching Ha-proxy and update it’s configuration file automatically on each time new Managed node (Configured With Apache Webserver) join the inventory. And Task 12.2 containing the setup of AWS instances.

Task overview

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.

2. Configure the same setup over AWS using instance over there.

Prerequisites

Here I am using Redhat-8 as a controller node & make sure that your controller node has proper internet connectivity.

as a controller node & make sure that your controller node has proper internet connectivity. Controller node has Ansible installed and configured to connect to our Ansible hosts using SSH keys. Make sure the control node has a regular user with sudo permissions and a firewall enabled.

has Ansible installed and configured to connect to our Ansible hosts using SSH keys. Make sure the control node has a regular user with sudo permissions and a firewall enabled. Now, We have to configure the ansible dynamic inventory so that we can fetch IP’s dynamically and then launch all the operating system over cloud then third and last setup load balancer through haproxy and my all the files and folder related to this task is in folder /ansible/arthtask12.2/

DYNAMIC INVENTORY SETUP

Here is the detail to setup the dynamic inventory on controller node to launch AWS instance using boto , ec2.yml and ec2.ini file & configure haproxy & webserver on it.

Follow the steps carefully for the setup of Dynamic Inventory

Step 1:

Install python3 “$ yum install python3 -y”

Install the boto3 and boto library

pip3 install boto3

pip3 install boto

Step2:

Create a directory “$ mkdir /ansible/arthtask12.2/mydb”

Download ec2.yml and ec2.ini from ansible official dynamic inventory GitHub link in /ansible/arthtask12.2/mydb folder. { both the files should be in same folder}

and from ansible official dynamic inventory GitHub link in folder. both the files should be in same folder} Make the ec2.py file executable by using “$ chmod +x ec2.py”

Step3:

export AWS_REGION='ap-south-1'

export AWS_ACCESS_KEY_ID='AKIAV3XXXXXXXXX'

export AWS_SECRET_ACCESS_KEY='/IloNROiarRhZxxxxxxxxxxxxxxxxxxxxx'

Step4:

A fter set this environmental variable just go to /root/.bashrc file and update this entry because every reboot the VM, this environmental variable lost automatically.

fter set this environmental variable just go to and update this entry because every reboot the VM, this environmental variable lost automatically. Now update this entry /ansible/arthtask12/mydb directory in ansible configuration file(/etc/ansible/ansible.cfg) and also set aws private_key and user through which you wanted to launch os on aws.

directory in and also set aws and through which you wanted to launch os on aws. Upload the instance private key location which we have created on AWS and update at /etc/ansible/ansible.cfg as highlighted in the following.

chmod 400 <private_key_name>

Dynamic inventory configuration is done now We can check using

ansible all --list-hosts

LAUNCH AWS OPERATING SYSTEM USING ANSIBLE PLAYBOOK

We need three operating system so we can use one for haproxy configuration and other two for webserver configuration.

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