1.Troubleshoot and Create Ansible Playbook

Published: (December 9, 2025 at 11:06 PM EST)
2 min read
Source: Dev.to

Source: Dev.to

Lab Information

An Ansible playbook needs completion on the jump host, where a team member left off. The inventory file /home/thor/ansible/inventory requires adjustments. The playbook must run on App Server 3 in Stratos DC. Update the inventory accordingly and create a playbook that creates an empty file /tmp/file.txt on App Server 3.

The validation will run the playbook with:

ansible-playbook -i inventory playbook.yml

Ensure the playbook works without any additional arguments.

Steps

Step 1 – Create the playbook directory

mkdir -p ~/playbook

Step 2 – Create the inventory file

vi ~/playbook/inventory

Add the following content:

[app_servers]
stapp01 ansible_user=tony ansible_password=Ir0nM@n owner_name=tony
stapp02 ansible_user=steve ansible_password=Am3ric@ owner_name=steve
stapp03 ansible_user=banner ansible_password=BigGr33n owner_name=banner

This defines all app servers.

Step 3 – Create the playbook file

vi ~/playbook/playbook.yml

Add the following:

---
- name: Create /home/opt.txt on all app servers
  hosts: app_servers
  become: yes

  tasks:
    - name: Ensure /home/opt.txt exists with correct permissions and ownership
      file:
        path: /home/opt.txt
        state: touch
        mode: "0744"
        owner: "{{ owner_name }}"
        group: "{{ owner_name }}"

Step 4 – Verify your files

# Inventory:
cat ~/playbook/inventory

# Playbook:
cat ~/playbook/playbook.yml

Step 5 – Run the playbook (validation will do this automatically)

ansible-playbook -i inventory playbook.yml

The playbook will:

  • Create /home/opt.txt on all app servers
  • Apply the correct ownership:
    • stapp01 → tony
    • stapp02 → steve
    • stapp03 → banner

Resources & Next Steps

Credits

  • All labs are from KodeKloud.
Back to Blog

Related posts

Read more »

What is DevOps?

Introduction If you search “What is DevOps?” online, you’ll find many complex definitions. In this article we’ll explain DevOps from the ground up. DevOps = De...