Ansible-Role For Httpd And Haproxy

Ansible-Role For Httpd And Haproxy

Hey Guys back with another interesting task in which I have configured apache Httpd and HAproxy package with the help of ansible-role.

No alt text provided for this image

Let's proceed techies 😊

First of all you all should know what is Apache Httpd , Haproxy and Ansible-Role🤔

Apache-Httpd : The Apache HTTP Server, colloquially called Apache, is a free and open-source cross-platform web server software, released under the terms of Apache License 2.0. Apache is developed and maintained by an open community of developers under the auspices of the Apache Software Foundation.

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.

Ansible-Role : In Ansible, the role is the primary mechanism for breaking a playbook into multiple files.This simplifies writing complex playbooks, and it makes them easier to reuse. The breaking of playbook allows you to logically break the playbook into reusable components.

Now after understanding the terminologies lets make the ansible roles for Httpd and HAproxy

Firstly I am going to make role of Httpd . So to make role we have to run the command 👇

ansible-galaxy role init httpd

After the role successfully created you have to configure task folder inside it .

No alt text provided for this image
No alt text provided for this image

Now configure vars folder 👇

No alt text provided for this image

Now after completion of this httpd we will make the role for HAproxy

ansible-galaxy role init haproxy

Again configure the task folder of HAproxy role

No alt text provided for this image
No alt text provided for this image

Now configure HAproxy configuration file and put it into template folder .

No alt text provided for this image

This configuration helps you in fetching ip's dynamically for backend servers. We have to specify front_port and back_port in vars folder .

No alt text provided for this image

We have to use the concept of notify and handlers so that if IP adds in backend server it restart the service of HAproxy . So you have to configure handler folder also .

No alt text provided for this image

After both roles configuration done , make a playbook and run both the roles inside it

No alt text provided for this image

Here hosts: proxy means HAproxy role will play in proxy node and hosts:web means httpd role will run in web nodes .

After this run the playbook 👉 ansible-playbook <playbook-name>.yml for example ansible-playbook task15.yml

No alt text provided for this image
No alt text provided for this image

Lets check from web-browser it is doing proxy or not

No alt text provided for this image
No alt text provided for this image

as you can see from above two images it is showing diff IP , so from that you can understand it is doing proxy .

Thank you !!!



To view or add a comment, sign in

More articles by Prabal Agrawal(He/Him)

Others also viewed

Explore content categories