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.
- 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.


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 ??
- 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/

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


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.