1.Troubleshoot and Create Ansible Playbook
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.txton all app servers - Apply the correct ownership:
stapp01 → tonystapp02 → stevestapp03 → banner
Resources & Next Steps
- Full Code Repository: KodeKloud Learning Labs
- More Deep Dives: Whispering Cloud Insights – read other technical articles
- Join Discussion: DEV Community – share your thoughts and questions
- Connect: LinkedIn
Credits
- All labs are from KodeKloud.