To Configure Reverse Proxy i.e. Haproxy and update it’s configuration file automatically on each time new Managed node join the inventory .

We first need to update the configuration file ,ie haproxy.cfg with Jinja .

Here I used ‘for loop’ in Jinja language for printing Groups (webserver) Value(Ip’s present in that group)

I created the architecture in the type like in future it would automatically update it’s configuration file on each time new Managed node join the inventory.

Before copying the haproxy.cfg file to the managed node

haproxy.cfg file in controller node

After copying the haproxy.cfg file to the managed node

haproxy.cfg file in managed node

Inventory File

Inventory file

After Working on the configuration file in the side of controller node ,I created a playbook which would automatically launch a webserver with a Load Balancer or Reverse proxy configured and also start the services .

In haproxy.yml playbook

haproxy.yml playbook

First Creating a play for webserver groups

Play for webserver

STEP 1

Creating a host ,ie webserver groups.

Host

STEP 2

Installing Httpd package with the help of package module .

Installing httpd package

STEP 3

Creating a simple html file in document root of managed node using the module copy.

Copying the webpage

STEP 4

Starting the Httpd Web Services using the module service.

Starting httpd services

STEP 5

Creating a Firewall rule for port no 80 with the protocol tcp using the module firewall.

Creating a Firewall Rule

Secondly creating a play for haproxy groups.

Play for haproxy

STEP 1

Creating a host ,ie haproxy groups.

Host

STEP 2

Installing haproxy package with the help of package module .

Installing haproxy

STEP 3

Copying the configuration file that we updated onto the controller node using the module template .

Copying the file

STEP 4

Starting the Haproxy service using the module service.

Starting haproxy service

STEP 5

Creating a Firewall rule for port no 8080 with the protocol tcp using the module firewall.

Creating a Firewall Rule

Now running haproxy.yml playbook

ansible-playbook haproxy.yml

Here my website is running with the Reverse proxy configured .

ThankYou .