πΎππππππππ ππΌπππππ
12.1 Use Ansible playbook to Configure Reverse Proxy i.e. Haproxy and update its configuration file automatically each time a new Managed node (Configured With Apache Web Server) joins the inventory.
ARE YOU TIRED OF DOING EVERYTHING MANUALLY??
DO YOU WISH TO HAVE INTELLIGENT AUTOMATION??
YOUR WEB SERVER IS FAILING AND WORRYING YOU A LOT??
YOU ARE NOT ABLE TO MANAGE MULTIPLE WEBSERVER??
IN THIS BLOG I AM GOING TO TELL YOU ABOUT INTELLIGENT AUTOMATION i.e, ANSIBLE
Are you thinking about what is ANSIBLE??
ANSIBLE
Ansible is an automation tool that is built on top of Python.
Ansible is used for configuration management, provisioning, and orchestration.
Ansible is a Declarative tool that is used for Configuration Management.
Ansible is Agentless means Ansible should be installed on the controller node only and there is no need to install it on the target node.
Ansible Manages inventory for target nodes.
IS IT GOOD TO GIVE MULTIPLE IP ADDRESS TO CLIENT SO THAT THEY CAN ACCESS THE AVAILABLE NODE OR WE SHOULD GIVE ONLY ONE IP TO THEM??
The answer to the above question is very simpleβ¦
But tell me do you like messy things or clean and disciplined??
The Technical answer to this question is to use Lα΄α΄α΄ Bα΄Κα΄Ι΄α΄α΄Κ and here we are using the tool Hα΄PΚα΄xΚ.
LOAD BALANCER
Load Balancer is the service companies use to manage multiple nodes so that if one node is busy then they can use another one.
Load Balancer manages the traffic that is coming to the website.
Load Balancer stays between Client device and Backend Servers.
HAPROXY
HaProxy is a tool that works as a REVERSE PROXY. The Client accesses the HaProxy server and HaProxy will call the webserver to open the page but in this overall process, the Backend Server is not exposed publicly. Clients can only access the HaProxy Server; it cannot access the Backend Server and this is a good practice for security purposes.
Letβs jump to the Practical partβ¦
MY FILES -
Created an inventory file that contains information about target nodes.
HaProxy configuration file contains the IP of Backend Server (Registration of backend server with HaProxy )
A webpage for testing purposes.
A YAML file that contains all the code for automation.
ANSIBLE INVENTORY
Inventory is the main part where all the target nodes' IPs are present. The inventory contains certain things about the target node -
- IP Address
2. Username
3. Password (if ssh key is not provided)
4. Connection type
The below image is of inventory file -
YAML CODE
Ansible Playbook is written in YAML language which will launch HaProxy server, web servers and in addition to this, it will configure HaProxy configuration file automatically.
- In the host, the Group name is given as βProxyβ so that it will pick that particular IP for HaProxy configuration.
- Under the tasks, The first module used is βpackageβ it will install haproxy software into the RHEL8 target node.
- The βtemplateβ module will copy the file and it supports jinja2 so it will dynamically add web servers' IPs into it.
- The βserviceβ module will start or stop the service.
- SELinux is used because it will not allow us to access the page so change its mode to βPermissiveβ.
- The firewall will not allow web pages to access by public people so stop it.
- The hosts allow only WebServer groups for the configuration.
- Package module will install software like httpd, php, net-tools.
- The template module will copy the code to the target node.
- The service module will start the service.
- Change the mode of SELinux.
HAPROXY CONFIGURATION FILE -
HaProxy is using 8080 port numbers and web server IPs are registered dynamically by jinja2 code.
WEBPAGE
The webpage will show the IP of the web server so that we can easily test the code as to whether itβs working well or not.
RUN ANSIBLE PLAYBOOK
[ ansible-playbook -v file.yml ] is the command to run the ansible-playbook where [ -v ] is verbosity which gives extra information while running the playbook.
AFTER RUNNING PLAYBOOK WHAT CHANGES SEEN ??
CONFIGURATION FILE UPDATED
IP of the webserver is registered in the HAPROXY configuration file.
WEB PAGE COPIED
The webpage is copied in both the web servers.
OUTPUT
THANK YOU FOR READING THIS ARTICLE!!
SHARING IS CARINGβ¦ KEEP LEARNINGβ¦