Geek Culture
Published in

Geek Culture

Created by Akanksha

Configure Apache Web Server, HAPROXY and further Auto-Register Backend Server IPs to HAPROXY using Ansible

roles controlling webserver versions and solving challenge for host IPs addition dynamically over each Managed Node in HAPROXY.cfg file which increases the scalability and high availability of our site…

🤔 What Ansible is ?

Automation is there in the world of IT from decades but Ansible is mainly designed for “Configuration Management”, the tool come to market with High Scalability and ability to kick Start the business, without giving high wages to employees and just Making Scripts to keep on configuring each node started by the Load Balancers……Go through my previous blog of Ansible where I have discussed the real industry use-case of Ansible. Click Here!!

🤔 Why we are using HAPROXY ?

HAProxy, which stands for High Availability Proxy, is a popular open source software TCP/HTTP Load Balancer and proxying solution which can be run on Linux, Solaris, and FreeBSD. Its most common use is to improve the performance and reliability of a server environment by distributing the workload across multiple servers (e.g. web, application, database).

🤔 What is the work of Apache HTTP Server ?

The basic job of all web servers is to accept requests from clients (e.g. a visitor’s web browser) and then send the response to that request (e.g. the components of the page that a visitor wants to see). Apache is the most popular web server.

Let’s Brief our Plan before Proceeding further:

  1. Firstly We will Create ansible.cfg file in which we would have to mention all the Managed nodes IP.
  2. Creating Static Inventory for all the Managed Node Metadata for the SSH connection that Ansible Create with playbook deployment from Controller Node.
  3. Creating Role For Apache Web Server Configuration.
  4. Creating Role for HAPROXY Configuration and auto-registration of Backend Web Server.
  5. Creating Setup.yml Ansible playbook file for deploying those Roles in order to achieve our Requirements.

Pre-Requisite:

# mkdir haproxy-ansible
# cd haproxy-ansible
# mkdir roles
# vim ansible.cfg
  1. Dynamic Inventory : Some Dynamic Inventory Scripts run on local Configuration Controller Machine and finding your Remote System information using which retrieves Address or DNS of the systems are loaded and the further Roles / Playbooks run on these inventory host setup on real time. These scripts are executable programs that collect information from external source and output the inventory in JSON format when passed the location of the remote system through ansible.cfg file or through -i option. This file is always executable and suits the environment where we are creating and destroying machines frequently and need to configure all at that time.
# mkdir roles
# cd roles
# ansible-galaxy init web
# ansible-galaxy init lbrole
# cd role/web/tasks
# vim main.yml
tasks.yml
# cd role/web/vars
# vim main.yml
var.yml
# cd role/web/files
index.html
# cd role/lbrole/tasks
# vim main.yml
tasks.yml
# cd role/lbrole/template
# cd role/lbrole/vars
# vim main.yml
# cd haproxy_ansible/
# vim setup.yml
# ansible-playbook setup.yml 

Thanks for reading. Hope this blog have given you some valuable inputs!!

(: — )

--

--

A new tech publication by Start it up (https://medium.com/swlh).

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store
Akanksha Singh

Platform Engineer | Kubernetes | Docker | Terraform | Helm | AWS | Azure | Groovy | Jenkins | Git, GitHub | Sonar | NMAP and other Scan and Monitoring tool