How to create ansible roles for web servers and load balancer | Technical EJ - Latest Technology News

Saturday, 10 April 2021

How to create ansible roles for web servers and load balancer

  Ekansh Jain       Saturday, 10 April 2021

Hi everyone, today I am going to perform an automation task using Ansible Tool.

The task we are going to perform is:

1) Create an Ansible role myapache to configure Httpd WebServer.
2) Create another ansible role myloadbalancer to configure HAProxy LB.
3) We need to combine both of these roles controlling web server versions and solving challenges for host IPs addition dynamically over each Managed Node in haproxy.cfg file.

Let's Start:


I am doing all my practical implementations on AWS Cloud by using EC2 instance

1) Firstly, we are going to create a webserverconfig yml file, so that we can easily configure httpd module in our managed nodes.

We have already set up our ansible's hosts file with groups, we had created two groups, webservers and loadbalancer as shown in a below image


2) Secondly
, we are going to create a loadbalancer(lbconfig) yml file, so that we can easily configure haproxy module in our managed node.

webserverconfig.yml file is given below


lbconfig.yml file is given below



haproxy.cfg file is shown below.

Here, we are using the jinja2 template for the dynamic nature. Using this jinja template we can dynamically able to add the new webserver with loadbalancer.


3) Now, we are going to create two roles, one is for the webserver and another one is for loadbalancer. See the below image.

we have created a roles directory, in this directory, we are going to create both roles(myapache and myloadbalancer).

In these roles, we have to do some copy-paste work like we have to copy our yml files and paste it inside the roles respectively.

See the image below:

This is the tasks' main.yml file for configuring apache webserver 


This is the tasks' main.yml file for configuring load balancer (haproxy)

See the image below:


4) After doing all the above steps, now we are ready to use these roles 

See the image below:


5) All set Now, Run the playbook 

6) Last step, Copy the public IP of the load balancer instance with the port number and paste it on the web browser to see the output.

Now, keep on refreshing the webpage, you will see that IPs is going to change again and again because of the load balancer



Thank You for reading my Article!! 

logoblog

Thanks for reading How to create ansible roles for web servers and load balancer

Newest
You are reading the newest post

No comments:

Post a comment

If you have any doubts, Please Comment down