✍CONFIGURE REVERSE PROXY USING ANSIBLE PLAYBOOK :

Priya Soni
8 min readApr 6, 2021

--

HELLO EVERYONE✌✌,

In this article, I will demonstrate How we can configure reverse proxy using ansible playbook.

And I will also show how to create our ansible playbook from the scratch . So , At the last we will configure HTTPD Web Server with the help of ansible playbook.

✍TASK DESCRIPTION :

We can configure reverse proxy using ANSIBLE PLAYBOOK!

  1. Use Ansible playbook to configure reverse proxy.
  2. Update its Configuration file automatically on its each managed node.
  3. And also configure apache webserver and join the inventory.

Before doing any practical implementations It’s a good practice to create one directory to store all the files.

This directory is also known as our Workspace. In my system I created one workspace called “task12”. I am putting everything in this workspace and at the end of this article I will provide the GitHub link, from where you can download this workspace and also use it.

But before starting let’s understand some basic terms.

✍What is Ansible ?

Ansible is an open-source IT automation engine, which can remove drudgery from your work life, and will also dramatically improve the scalability, consistency, and reliability of your IT environment.

ANSIBLE

✍What is Ansible and what can it automate?

You can use Ansible to automate three types of tasks:

👉Provisioning: Set up the various servers you need in your infrastructure.

👉Configuration Management: Change the configuration of an application, OS, or device; start and stop services; install or update applications; implement a security policy; or perform a wide variety of other configuration tasks.

👉Application Deployment: Make DevOps easier by automating the deployment of internally developed applications to your production systems.

Ansible can automate IT environments whether they are hosted on traditional bare metal servers, virtualization platforms, or in the cloud. It can also automate the configuration of a wide range of systems and devices such as databases, storage devices, networks, firewalls, and many others.

The best part is that you don’t even need to know the commands used to accomplish a particular task. You just need to specify what state you want the system to be in and Ansible will take care of it.

✍Why we need Ansible?

There are many other IT automation tools available, including more mature ones like Puppet and Chef, so why would you choose Ansible? The main reason is simplicity.

Michael DeHaan, the creator of Ansible, already had a lot of experience with other configuration management tools when he decided to develop a new one.

He said that he wanted “a tool that you could not use for six months, come back to, and still remember.”

✍WHAT IS AN ANSIBLE-PLAYBOOK ?

An Ansible playbook is an organized unit of scripts that defines work for a server configuration managed by the automation tool Ansible. Ansible is a configuration management tool that automates the configuration of multiple servers by the use of Ansible playbooks. It is written in YAML language.

✍What is Load Balancer ?

Load balancing is defined as the methodical and efficient distribution of network or application traffic across multiple servers in a server farm. Each load balancer sits between client devices and backend servers, receiving and then distributing incoming requests to any available server capable of fulfilling them.

LOADBALANCER

✍What is HaProxy Load Balancer ?

HaProxy (High Availability Proxy) is a TCP/HTTP load balancer and proxy server that allows a webserver to spread incoming requests across multiple endpoints.

This is useful in cases where too many concurrent connections over-saturate the capability of a single server.

✍ WHAT IS WEBSERVER ?

A web server is a computer that runs websites. It’s a computer program that distributes web pages as they are requisitioned. The basic objective of the web server is to store, process and deliver web pages to the users. This intercommunication is done using Hypertext Transfer Protocol (HTTP).

So, Without wasting your time let’s start our practical implementation part….

👉TO CONFIGURE ANSIBLE IN OUR OS :

In this task , first we have to install Ansible using this command

# pip3 install ansible

Now we have to check our ansible version using this command.

# ansible — version

Now we have to be check how many hosts we have right now.

So as you can see that there is no hosts in my managed node.

Now we need to make a file ip.txt and provide the IP of our managed node.

# vim ip.txt

My Load Balancer is setup in IP 192.168.1.5

And My Web Server is setup in IPs are 192.168.1.4 and 192.168.6

Then we have to make changes in the ansible configuration file.

# vim /etc/ansible/ansible.cfg

Now make a new directory for the ansible playbook using this command.

# mkdir task12

# cd /task12

✍ To Writing the Ansible-playbook for Haproxy load balancer :

We have to run following commands which is given below :-

# cd /etc/haproxy/

# ls

# vim haproxy.cfg

👉NEXT :

👉NEXT :

We have to write our ansible playbook and also give the .yml extension which is complusory.

# vim lb.yml

After writing the code we will check the syntax of our code and it will not show any error if its correct.

# ansible-playbook — syntax-check lb.yml

Now I have to show my code lb.yml for your reference.

👉 NEXT :

then finally we have to be run our Ansible-Playbook.

# ansible-playbook lb.yml

👉 NEXT :

👉 NEXT :

👉 LOAD BALANCER AFTER IT’S CONFIGURATION :

# systemctl status haproxy

👉HAPROXY AFTER IT’S CONFIGURATION :

# vim /etc/haproxy/haproxy.cfg

Then you can open the firefox and write the ip and port number in the format which is given below:-

For accessing the webpage:-

Syntax : IP:Port (IP of the load balancer) For eg.: 192.168.1.5:1443

Now we have to be go to our target node and check httpd is configure or not.

for this we have to be run following commands :-

👉FOR TARGET NODE 1 :

# rpm -q httpd

# systemctl status httpd

# netstat -tnlp | grep httpd

👉 NEXT :

Webserver after configuration :

👉 NEXT :

Then you can open the firefox and write the ip and port number in the format which is given below:-

For accessing the webpage :-

Syntax : IP:Port

For example: 192.168.1.6:80

👉SAME FOR TARGET NODE 2 :

Webserver after configuration :

Then you can open the firefox and write the ip and port number in the format which is given below:-

For accessing the webpage :-

Syntax : IP:Port

For example: 192.168.1.4:80

Finally I have successfully completed my this task. Thank you Vimal Daga sir for giving me such a great task. Sir your mentorship is a God gift for me to enhance my skills and I am very blessed because you are my mentor.

So guys, In the upcoming days I am going to be publish a lots of blogs and articles on different different automation tools and other technologies, So definetely follow me on Medium as well as on linkedin.

I have also provide the link of my Github repository for this task which is given below for your reference.

So, Here is my linkedin profile if you have any queries definitely comment below or DM me on linkedin.

THANK YOU🙏🙏 GUYS FOR READING MY BLOG…

KEEP LEARNING🙇‍♂️📖🙇….

KEEP SHARING✌✌….

--

--

Priya Soni
Priya Soni

No responses yet