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
webserverconfig.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
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
No comments:
Post a Comment
If you have any doubts, Please Comment down