CONFIGURING_WEB_SERVER_AND_LAUNCHING_LOAD_BALANCER_BY_HAPROXY_USING_ANSIBLE_PLAYBOOK

Swarnim Kashyap
5 min readDec 13, 2020

--

What is ansible?

Ansible is a software tool that provides simple but powerful automation for cross-platform computer support. It is primarily intended for IT professionals, who use it for application deployment, updates on workstations and servers, cloud provisioning, configuration management, intra-service orchestration, and nearly anything a systems administrator does on a weekly or daily basis. Ansible doesn’t depend on agent software and has no additional security infrastructure, so it’s easy to deploy.

How Ansible works?

In Ansible, there are two categories of computers: the control node and managed nodes. The control node is a computer that runs Ansible. There must be at least one control node, although a backup control node may also exist. A managed node is any device being managed by the control node.

Ansible works by connecting to nodes (clients, servers, or whatever you’re configuring) on a network, and then sending a small program called an Ansible module to that node. Ansible executes these modules over SSH and removes them when finished. The only requirement for this interaction is that your Ansible control node has login access to the managed nodes. SSH keys are the most common way to provide access, but other forms of authentication are also supported.

What is Ansible playbooks?

While modules provide the means of accomplishing a task, the way you use them is through an Ansible playbook. A playbook is a configuration file written in YAML that provides instructions for what needs to be done in order to bring a managed node into the desired state. Playbooks are meant to be simple, human-readable, and self-documenting. They are also idempotent, meaning that a playbook can be run on a system at any time without having a negative effect upon it. If a playbook is run on a system that’s already properly configured and in its desired state, then that system should still be properly configured after a playbook runs.

A playbook can be very simple, such as this one that installs, as a privileged user, the Apache HTTP server on any node in an IT department’s webservers group:

- name: Apache server installed
hosts
: webservers
become
: yes

Playbooks can also be very complex, with conditionals and variables. However, because most of the real work is done by Ansible modules, playbooks remain brief, readable, and clear even though they can orchestrate entire networks of managed nodes.

What is HAProxy?

HAProxy is a high-performance, open-source load balancer reverse proxy for TCP and HTTP applications. Users can make use of HAProxy to improve the performance of websites and applications by distributing their workloads. Performance improvements include minimized response times and increased throughput. HAProxy is used in high traffic services such as GitHub and Twitter.

Load balancers can be used to distribute workloads across computers, networks, disk drives or CPU”s . HAProxy, included in many distributions of Linux, is one of the leading standards in software load balancing.

Its mode of operation makes its integration into existing architectures very easy and riskless, while still offering the possibility not to expose fragile web servers to the net, such as below :

What Is Apache Web Server?

Apache is a popular open-source, cross-platform web server that is, by the numbers, the most popular web server in existence. It’s actively maintained by the Apache Software Foundation.

Some high-profile companies using Apache include Cisco, IBM, Salesforce, General Electric, Adobe, VMware, Xerox, LinkedIn, Facebook, Hewlett-Packard, AT&T, Siemens, eBay, and many more (source).

In addition to its popularity, it’s also one of the oldest web servers, with its first release all the way back in 1995. Many cPanel hosts utilize Apache today. Like other web servers, Apache powers the behind-the-scenes aspects of serving your website’s files to visitors.

Because Apache doesn’t perform as well in some benchmarks, especially for static websites or websites with high traffic, Kinsta uses the NGINX web server instead of Apache. Though NGINX hasn’t been around for as long as Apache, it’s quickly grown in popularity and market share since its launch in 2004.

Let’s start with the practical part:

We have require:👇

1. Managed Node .

2. Target Node.

We have to move into “cd/etc/ansible/ansible.cfg” this perticular file tell that this is my default configuration and my IP is store in that given directory.

To check the connectivity we have to use above command given in the image: ansible all -m ping

“ vim /etc/haproxy/haproxy.cfg” In this file we have to defined about our backend , First of all your backend will work as a Load Balancer with a mechanism called Roundrobin,and here we have to give all our webserver. This for which we use above it will help us to automatically fetch all the IP given to Target Node so that we can easily apply haproxy configuration here.

In the above image i have written my entire ansible-playbook for configuring webserver and Loadbalancer by haproxy 👆.

In the above image i mentioned my index.php file in which i ask to run ifconfig command over the apache webserver.

It’s time to run our Ansible-Playbook:

I use “ansible-playbook lb.yml” this command to run my play book.

In the above image we have seen that our playbook is running succcessfully now its time to check that webserver is working good or not.

Now what we see in the above image we have configure my first target node at port no: 8080 and when we refresh the webpage we see that its show IP of our second target node.👇

Now we have successfully configure our apache webserver and load Balancer by Haproxy Over the RedHat..

BY- SWARNIM KASHYAP

--

--

Swarnim Kashyap

RedHat Certified Engineer| DevOps Enthusiast | Big Data Hadoop | RedHat Linux 8| AWS Cloud | GCP | Azure Cloud |GIT & GitHub |Python