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.
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 .
Now configure vars folder 👇
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
Now configure HAproxy configuration file and put it into template folder .
This configuration helps you in fetching ip's dynamically for backend servers. We have to specify front_port and back_port in vars folder .
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 .
After both roles configuration done , make a playbook and run both the roles inside it
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
Lets check from web-browser it is doing proxy or not
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 !!!