HOW TO CONFIGURE HAPROXY USING ANSIBLE IN RHEL8

shristi sharma
4 min readDec 10, 2020

What is Ansible👉

🟡Ansible is simple open source IT engine which automates application deployment, intra service orchestration, cloud provisioning and many other IT tools.

🟡Ansible uses playbook to describe automation jobs, and playbook uses very simple language i.e. YAML (It’s a human-readable data serialization language & is commonly used for configuration files, but could be used in many applications where data is being stored)which is very easy for humans to understand, read and write. Hence the advantage is that even the IT infrastructure support guys can read and understand the playbook and debug if needed (YAML — It is in human readable form).

🟡Ansible is designed for multi-tier deployment. Ansible does not manage one system at time, it models IT infrastructure by describing all of your systems are interrelated. Ansible is completely agentless which means Ansible works by connecting your nodes through ssh(by default). But if you want other method for connection like Kerberos, Ansible gives that option to you.

🟡After connecting to your nodes, Ansible pushes small programs called as “Ansible Modules”. You can configure as many nodes at the same time.

🟡Ansible runs that modules on your nodes and removes them when finished. Ansible manages your inventory in simple text files (These are the hosts file). Ansible uses the hosts file where one can group the hosts and can control the actions on a specific group in the playbooks.

What is HAproxy👉

🟡 HAProxy is installed with RightScale load balancer Server Templates. Load-balancer servers are also known as front-end servers. Generally, their purpose is to direct users to available application servers. A load-balancer server may have only the load balancer application (HAProxy) installed or, in rare cases, it may be an application server in addition to a load balancer, which is not a recommended configuration.

🟡Each load-balancer server has its own public IP address (typically an Elastic IP address in the case of Amazon EC2 clouds), but shares the same fully qualified domain name (e.g. host.domain.tld) as the other load-balancer servers in your configuration.

🟡Example: Server A: loadbalancer.example.com (IP address: 174.11.45.13), Server B: loadbalancer.example.com (IP address: 174.11.68.201).

🟡 can be used with HTTP and HTTPS traffic.

Configure Reverse Proxy i.e Haproxy using Ansible Playbook:

Stepwise procedure

Setup required

✔One controller node and one target node

✔Controller node → my controller node will work as frontend users and it name it as loadbalancer

✔Target node/Managed node → my target node also called backened in this task it is named as webserver

✔So in total we are using two different IP’s

Rough Procedure(overview of task what we need to do)

Step 1 👉Install haproxy software in your frontend node

Step 2👉Configure the Reverse proxy and give them the frontend and backend IP in their confg file setup

Step3👉Start the haproxy services

Lets Start The Procedure

Open the IP inventory file where you have given the name to your controller and managed node. Use command vim/root/tp.txt

Always check the connectivity between the nodes:

Create the workspace in your vim named it and start conf your file in one single workspace or directory

So we have created the playbook name load.yml where we will write all the code that was needed to perform in this task.

Lets See the configuration file of haproxy.cfg.j2 what changes we have made in it . We have manually made the changes in the file then this file has been uploaded to the main confg file while using ansible copy module

FINAL PLAYBOOK👉

PLAYBOOK OUTPUT

FINAL RESULT👉

Lets check whether the services are running

As you can see our load balancer IP is fetching data form the webserver ip this show that our task is succesfully working.

Our Playbook is running successfully. So viewers repeat the above steps to configure HAproxy on rhel8 using ansible . Any Suggestion Is Valuable Fell Free To Ask.😊

BY -Shristi Sharma

--

--

shristi sharma

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