Ansible Blockinfile Module

Ansible Blockinfile Module

ยท

2 min read

Task Requirements:

The DevOps team wants to install and set up a simple httpd web server on all app servers in the Datacenter. Additionally, they want to deploy a sample web page for now using Ansible only. Therefore, write the required playbook to complete this task. Find more details about the task below.

  • We already have an inventory file under /home/thor/ansible directory on jump host. Create a playbook.yml under /home/thor/ansible directory on jump host itself.

  • Using the playbook, install httpd web server on all app servers. Additionally, make sure its service should up and running.

  • Using blockinfile Ansible module add some content in /var/www/html/index.html file. Below is the content:

Welcome to XfusionCorp!

This is Nautilus sample file, created using Ansible!

Please do not modify this file manually!

  • The /var/www/html/index.html file's user and group owner should be apache on all app servers.

  • The /var/www/html/index.html file's permissions should be 0655 on all app servers.

Execution:

  1. Navigate to the directory mentioned in task requirements and create the playbook.yml file.

  2. Content of the playbook.yml file used can be found in this link >>> https://github.com/mightygull/Ansible-Playbooks/blob/main/ansible_blockinfile_module.yml

  3. Run the following command to execute the playbook
    ansible-playbook -i inventory playbook.yml

  4. Validate the task by running the curl command on app server to check. First we run this command to check the content of the specific directory listed in the inventory file.
    ansible all -a 'ls -l /var/www/html/' -i inventory

    Then we run the curl command against each web server hostname to check.

ย