Troubleshoot and Create Ansible Playbook Level 1 Ansible KodeKloud Engineer Task

Ticker

6/recent/ticker-posts

Troubleshoot and Create Ansible Playbook Level 1 Ansible KodeKloud Engineer Task

 QuestionAn Ansible playbook needs completion on the jump host, where a team member left off. Below are the details:

The inventory file /home/thor/ansible/inventory requires adjustments. The playbook must run on App Server 3 in Stratos DC. Update the inventory accordingly.

Create a playbook /home/thor/ansible/playbook.yml. Include a task to create an empty file /tmp/file.txt on App Server 3.

Note: Validation will run the playbook using the command ansible-playbook -i inventory playbook.yml. Ensure the playbook works without any additional arguments.

Please Note:-  Perform the below commands based on your question server,  user name & other details that might differ. So please read the task carefully before executing it. 

All the Best 👍

Solution:  

1. Create a inventory file and add the app server as per your task

thor@jump_host /$ vi /home/thor/ansible/inventory                      

thor@jump_host /$ cat /home/thor/ansible/inventory

stapp03 ansible_host=172.16.238.12 ansible_user=banner ansible_ssh_pass=BigGr33n   

thor@jump_host /$    

2. Create a Playbook file 

thor@jump_host /$vi /home/thor/ansible/playbook.yml

thor@jump_host /$cat /home/thor/ansible/playbook.yml

- name: Create file in appserver

  hosts: stapp03

  become: yes

  tasks:

    - name: Create the file

      file:

        path: /tmp/file.txt

        state: touch


thor@jump_host /$ 

3.  Post file saved, run below command to execute the playbook

thor@jump_host ~/ansible$ ansible all -a "ls -ltr /tmp/" -i inventory

stapp03 | CHANGED | rc=0 >>

total 4

drwx------ 2 banner banner 4096 Aug  3 15:20 ansible_command_payload_crUi5o

thor@jump_host ~/ansible$

thor@jump_host ~/ansible$ ansible-playbook -i inventory playbook.yml

 

PLAY [Create file in appserver] *************************************************

 

TASK [Gathering Facts] **********************************************************

ok: [stapp03]

 

TASK [Create the file] **********************************************************

changed: [stapp03]

 

PLAY RECAP **********************************************************************

stapp03                    : ok=2    changed=1    unreachable=0    failed=0    skipped=0    rescued=0    ignored=0  

 

thor@jump_host ~/ansible$

thor@jump_host ~/ansible$ ansible all -a "ls -ltr /tmp/" -i inventory

stapp03 | CHANGED | rc=0 >>

total 4

-rw-r--r-- 1 root   root      0 Aug  3 15:21 file.txt

drwx------ 2 banner banner 4096 Aug  3 15:21 ansible_command_payload_Dcfc5t

thor@jump_host ~/ansible$


4.  Click on Finish & Confirm to complete the task successfully

Happy Learning!!!!


Apart from this if you need more clarity,  I have made a  tutorial video on this, please go through and share your comments. Like and share the knowledge

Post a Comment

0 Comments

Latest Posts

Troubleshoot and Create Ansible Playbook Level 1 Ansible KodeKloud Engineer Task