100-Days-Of-DevOps-Challenge-KodeKloud

Using Ansible Conditions

The Nautilus DevOps team had a discussion about, how they can train different team members to use Ansible for different automation tasks. There are numerous ways to perform a particular task using Ansible, but we want to utilize each aspect that Ansible offers. The team wants to utilise Ansible’s conditionals to perform the following task:

An inventory file is already placed under /home/thor/ansible directory on jump host, with all the Stratos DC app servers included.

Create a playbook /home/thor/ansible/playbook.yml and make sure to use Ansible’s when conditionals statements to perform the below given tasks.

  1. Copy blog.txt file present under /usr/src/itadmin directory on jump host to App Server 1 under /opt/itadmin directory. Its user and group owner must be user tony and its permissions must be 0655 .

  2. Copy story.txt file present under /usr/src/itadmin directory on jump host to App Server 2 under /opt/itadmin directory. Its user and group owner must be user steve and its permissions must be 0655 .

  3. Copy media.txt file present under /usr/src/itadmin directory on jump host to App Server 3 under /opt/itadmin directory. Its user and group owner must be user banner and its permissions must be 0655.

NOTE:

Steps

  1. Move into ansible directory and check files

     cd ansible
     ls -la
     cat inventory
    
  2. Create an empty playbook.yml file

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

    • Make sure you have update src path and mode based on your task description
  4. Run the playbook

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

    • login into each app server and run the command
     ls -la /opt/itadmin
    

Good to Know