Deploy Reverse Proxy on top of the AWS Instance using ansible playbook.

shristi sharma
4 min readDec 13, 2020

We were going to provision our instance on AWS then we will configure HAproxy using ansible playbook

Setup Required

  1. One controller node

2. Two target/ managed node.

My controller node will launch on👉 rhel8

My target node will launch on 👉AWS instance and the whole task is performed on top of AWS instance .

Procedure

  1. We need to launch the OS on AWS instance so we need to write the playbook for that.
  2. Second when the OS will launched we will configured the HAproxy over there using playbook.

So follow the step below for provisioning our AWS👇

part 1 launching OSon AWS

PART 1

First of all we need to create the directory inside our vm named it as ws5 and create folder inside this .

We will discuss all in detail which folder is useful for which task

Before starting the task always check the connectivity by following command.

ansible all — m ping

Then went to the confg file of ansible by the following command

vim /etc/ansible/ansible.cfg

Lets discuss this configuration file in detail 👇

  • Inventory = This file contain managed and target node IP
  • host_key_checkings = false

Ansible works on the protocol called ssh for linux OS. So we need to disable the ssh key, so that when we do ssh it doesnot ask key from the user.

  • remote_user = We need to give user name because we are login inside the AWS instance
  • private_key_file = we need to give the private key that we have downloaded while launching aws instance
  • ANSIBLE_NOCOWS = 1 and nocows = true
  • while running the playbook in my output I am getting cows so for that we need to disable that cow while writing this command in the confg file .
  • NOTE- This command will used by those user who are facing this problem rest can ignore this

[Privilege escalation]

While logging inside the aws that we have launched we need to first login with sudo command otherwise it will throw one error so for that we need to write this four command

  • become = true
  • become_method = sudo
  • become user = root
  • become_ask_pass = false

After doing this save and exit the file

Now went to host.txt file where we have wriiten our IP

vim /root/host.txt ✏👇

now we have setup everything that is required like our host and configuration file now we are going to write a playbook that will launched our web instances on AWS cloud

FIRST TASK IS TO INSTALL SOFTWARE THAT IS REQUIRED

✔YUM INSTALL Python3

✔YUM INSTALl BOTO

✔YUM INSTALL BOTO3

NEXT STEP

Go to vim /cloud.yml file that you have created in your directory write the whole code save and then exit

For launching AWS instance we need to provide the key like
region , image, instance_type , vpc_subnet_id, group_id, key_name, state ,count aws_access_key , aws_secret_key

📍 Here count = 2 because we are going to launch two instances to see our demo you can give any no of count also give your access and secret key that is confidential we didnot need to share this with anyone🤫

RUN THIS PLAYBOOK😊

So we can see we have launched two webserver named web1 and web2 on aws successfully using playbook🤞

PART 2

NOW WE HAVE TO DEPLOYED HAPROXY

now we are going to deploy haproxy server ie Reverse proxy on rhel8 we need to write playbook written below

Lets see what changes we have made in the configuration file of

vim /root/haproxy/haproxy.cfg

Finally save and run the code 😁

SHOW TIME

As you can see we can see the webpage successfully on port no 8080 and the Ip that has been given is of localhost i.e. (IP: port no)

FINALLY WE DID IT

By👉 SHRISTI SHARMA

--

--

shristi sharma

Aspiring Devops Enthusiastic |Content Creator |Python | Machine Learning | Cloud Computing