Vineet Negi
3 min readDec 24, 2020

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.

What is 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 (in terms of processor and memory usage).

Let’s Configure haproxy over the AWS cloud.

  1. Launch minimum 3 instances -:
  • one controller node(CN)
  • two managed node(MN)

2. Transfer you private .pem to the CN. I used winSCP to transfer the key from local to the instance.

3. Installing Ansible

pip3 install ansible

For better management i create a directory called ansi and there i put all my files/folder

Setting up Configuration file and inventory file at loc /etc/ansible/. before setting up make sure that ansible directory is there in /etc/ location else create one.

Configuration File
Inventory_file

4. After done with the installation you’ll notice that as a root user you won’t be able to run ansible command. But it’s already installed.

How to resolve this ??

  1. EXIT from root account then run ansible command

2. The issue is due to path variable is not set for root. Let’s set path variable.

location of ansible -> /usr/local/bin/
THE ABOVE PATH IS NOT SET

SETTING PATH FOR ANSIBLE COMMANDS

export PATH="$PATH:<PATH_NAME>"
EX.
export PATH="$PATH:/usr/local/bin/"

THIS PATH IS TEMPRORARY. You can make it permanent. Use .bashrc file.

Now run ansible as a root user it will work.

5. Configuring WebServer

negi.php

6. Configuration LoadBalancer

Output:-

SAME TASK CAN BE DONE OVER THE LOCAL VIRTUAL MACHINE AND THERE ONLY CHANGE IS IN THE INVENTORY THERE WE WILL GIVE SSH PASSWORD INSTEAD OF PROVIDING KEY_FILE.

Sign up to discover human stories that deepen your understanding of the world.

Free

Distraction-free reading. No ads.

Organize your knowledge with lists and highlights.

Tell your story. Find your audience.

Membership

Read member-only stories

Support writers you read most

Earn money for your writing

Listen to audio narrations

Read offline with the Medium app

Vineet Negi
Vineet Negi

Written by Vineet Negi

★ Aspiring DevOps Engineer ★ Technical Volunteer @LinuxWorld ★ Technical Content Writer @Medium ★ ARTH Learner

No responses yet

Write a response