100-Days-Of-DevOps-Challenge-KodeKloud

Ansible Lineinfile Module

The Nautilus DevOps team want to install and set up a simple httpd web server on all app servers in Stratos DC. They also want to deploy a sample web page using Ansible. Therefore, write the required playbook to complete this task as per details mentioned below.

We already have an inventory file under /home/thor/ansible directory on jump host. Write a playbook playbook.yml under /home/thor/ansible directory on jump host itself. Using the playbook perform below given tasks:

  1. Install httpd web server on all app servers, and make sure its service is up and running.
  2. Create a file /var/www/html/index.html with content:

     <p> This is a Nautilus sample file, created using Ansible! <p>
    
  3. Using lineinfile Ansible module add some more content in /var/www/html/index.html file. Below is the content:

     <h1> Welcome to xFusionCorp Industries!</h1>
    

    Also make sure this new line is added at the top of the file.

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

  5. The /var/www/html/index.html file’s permissions should be 0755 on all app servers.

Note: Validation will try to run the playbook using command ansible-playbook -i inventory playbook.yml so please make sure the playbook works this way without passing any extra arguments.

Steps

  1. Move into ansible directory and look at the inventory file

     cd ansible
     cat inventory
    
  2. Create an empty playbook.yml file:

     touch playbook.yml
    
  3. Update playbook.yml with the contents from this YAML file

  4. Run the playbook command:

     ansible-playbook -i inventory playbook.yml
    
  5. Verify with curl

     curl http://stapp01
     curl http://stapp02
     curl http://stapp03
    

Good to Know