๐ŸŒ Deploy webpage to two different webservers and display the OS name and Kernel version in the webpage ๐ŸŒ

๐ŸŒ Deploy webpage to two different webservers and display the OS name and Kernel version in the webpage ๐ŸŒ

ยท

3 min read

Introduction:-

To fulfill the task, it is required to configure the web package and then deploy the webpage

Requirements:-

  • Two virtual machines created in Oracle Virtual box or two managed nodes created in AWS

  • Controller node with ansible installed and configured

Tasks:-

  • Add the IP address or alias of the managed nodes which will be used as webserver and test the connection to the inventory file

  • In the controller node, start developing the playbook.

  • Declare the variables in โ€œvarsโ€ section of the playbook:

  • Write the 1st task to install the โ€œhttpdโ€ package

  • Write the 2nd task to create a directory. That need to be used document root which is different from /var/www/html location

  • Create an webpage with following content and write the task with โ€œtemplateโ€ module to place it to new defined document root.

  • Here, ansible_facts is a default variable in ansible which contains the information of software and hardware of the machine. ansible_distribution is sub-parameter which is used to display the OS name installed in the machine and ansible_kernel is the another sub-parameter to display the kernel version. The detail can also be found by running adhoc command: ansible server_ip -m setup

  • The jinja template has been used here to pull the value of variable which are mentioned in โ€œvarsโ€ section of the playbook.

  • As per the requirement, a new configuration file need to be prepared to have the document root as /var/www/newweb and port as 81 which need to be placed in /etc/httpd/conf.d location.

Template module will consider the jinja template and it will replace the content within {{ }} with its actual value which is not the case for copy module. It used to consider the entire content as collection of string and transfer it to the target location as it is. The jinja template has been used in configuration file as well to pull the value of string mention within {{ }} from โ€œvarsโ€ section of the playbook.

  • Write the task, to start the webservice with service module. The service need to be started at the end of all configuration.

  • At the end, a handler has been written which is mentioned to be called if there is any change in webpage or configuration file.

  • The entire playbook will look like below:

  • Execute the playbook with below command:ansible-playbook playbook.yml

  • Once the status is successful the curl command can be used to test the output abd we will be able to see that the content is getting displayed as per the requirement:

Thank you!!

ย