An Ansible playbook run completes with the following summary:
PLAY RECAP: webserver01 : ok=8 changed=5 unreachable=0 failed=1 skipped=2 rescued=0
What does "changed=5" indicate?
Ansible reports a distinct outcome for every task execution. Understanding the PLAY RECAP counters is essential for interpreting automation results:
Counter
Meaning
Example
ok
Task ran, system already in desired state — no change made
Package already installed
changed
Task ran and modified the system
Config file was updated, service was restarted
failed
Task encountered an error and aborted
Non-zero exit code from a shell command
skipped
Task was skipped — when: condition evaluated to false
Deploy task skipped because target is already at latest version
unreachable
SSH connection to host failed
Host is down or firewalled
Idempotency health check: Run the same playbook twice. If the second run shows changed=0, your playbook is idempotent — it only changes what needs to change.
2 / 15
A new engineer asks about the Ansible role directory structure: tasks/, handlers/, vars/, defaults/, templates/, and files/.
What is the purpose of the handlers/ directory?
Handlers are special tasks that are "notified" by regular tasks and run at the end of a play (after all tasks complete), and only if they were notified.
Handler runs once even if notified by 10 tasks — prevents multiple restarts
Execution timing
After all tasks in the play, unless meta: flush_handlers is used mid-play
Conditional triggering
Only runs if the notifying task reported "changed" — not if "ok"
3 / 15
During a code review, a senior engineer comments: "This Ansible task is not idempotent — it will fail or cause side effects on repeated runs."
What does idempotency mean in an Ansible context?
Idempotency = a task checks current state before acting; it only makes changes when needed. This is the core design principle behind Ansible modules.
Module
Idempotent?
Reason
apt / yum
✓ Yes
Checks if package is already installed; "ok" if so
template / copy
✓ Yes
Compares file checksum; only writes if content differs
command / shell
✗ Not by default
Runs unconditionally — use creates: or removes: to add a condition
service
✓ Yes
Checks service state before starting/stopping
Convergence = the process of applying idempotent automation until the system reaches the desired state. If the system is already converged, re-running causes no changes.
4 / 15
An Ansible inventory file defines the following groups:
Ansible inventory groups use the [group:vars] syntax to define variables scoped to that group. [all:vars] is the special "all hosts" group's variable section.
Variable precedence (low → high)
Role defaults (defaults/main.yml)
Inventory [all:vars]
Inventory group vars ([webservers:vars])
Inventory host vars
Playbook vars: block
Extra vars (-e flag, highest precedence)
Dynamic inventory — instead of a static file, a script or plugin generates the inventory from a cloud provider API at runtime (AWS EC2 plugin, GCP plugin)
host_vars / group_vars directories — preferred alternative to inline inventory variables for larger projects
5 / 15
A DevOps team is growing and is asked to migrate from flat Ansible playbooks to a role-based structure. When should you use Ansible roles instead of a flat playbook?
Roles solve the reusability and maintainability problems of large flat playbooks:
Approach
Best for
Trade-offs
Flat playbook
One-off scripts, quick automation tasks
Simple, no structure overhead; hard to reuse
Role
Team-maintained, reusable automation components
Structured, testable (Molecule), shareable via Galaxy
Ansible Galaxy — community registry for sharing and consuming roles (like npm for Ansible)
Molecule — testing framework for Ansible roles: spins up containers/VMs, runs the role, verifies the outcome
role dependencies — a role can declare that it requires other roles to run first (meta/main.yml)
6 / 15
Sarah from the infrastructure team sent you this Slack message: 'Hey, I'm trying to update the firewall rules on our webservers using Ansible, but it keeps failing. The error says 'No such file or directory'. I've checked the paths in my playbook and they seem correct. Any ideas?' What is the most likely reason for this error?
Sarah's message indicates a common Ansible problem: incorrect file paths. The 'No such file or directory' error signifies that Ansible cannot find the files it's trying to modify based on the specified path within the playbook. This often happens if a typo exists in the path or the files have been moved since the playbook was last created. It's unlikely she's experiencing network instability, user configuration issues, or syntax errors without more context.
7 / 15
David in the code review is pointing out this comment: 'This Ansible task uses `apt update && apt install` – it will repeatedly try to upgrade packages every time the playbook runs, even if they're already up-to-date. This isn't idempotent and could cause issues.' What does David mean by 'idempotency' in this context?
Idempotency is a core concept in Ansible and DevOps. It means a playbook task should produce the same outcome regardless of how many times it's executed – essentially, it should leave the system in its desired state without making unnecessary changes. David's comment highlights the problem with using commands like `apt update && apt install` which will always attempt to upgrade packages, even if they are already up-to-date, violating this principle.
8 / 15
You're writing a PR description for an Ansible playbook that installs and configures a web server. The PR includes the following section: 'This playbook uses variables defined in the defaults/main.yml file to customize the web server settings.' What is the primary benefit of using variables stored in a file like defaults/main.yml?
Using variables in a file like defaults/main.yml promotes reusability and flexibility. This approach allows you to easily adapt the playbook for different environments by simply modifying the values within that file – without needing to change the core logic of the playbook itself. This is crucial for managing configurations across various stages of deployment.
9 / 15
You've been asked to create an Ansible playbook that manages the deployment of a database server. The inventory file defines the following group: [databases] db01.example.com. What does this line in the inventory file represent?
This line specifies the *hostname* and *IP address* of the database server (db01.example.com) that Ansible will manage. The inventory file is used to define the servers that Ansible interacts with; this particular entry tells Ansible which server it's targeting for configuration management.
10 / 15
Sarah from the infrastructure team sent you this Slack message: 'Hey, I'm trying to update the firewall rules on our webservers using Ansible, but it keeps failing. The error says 'No such file or directory'. I've checked the paths in my playbook and they seem correct. Any ideas?' What is the most likely reason for this error?
Sarah's message indicates a common Ansible problem: incorrect file paths. The 'No such file or directory' error signifies that Ansible cannot find the files it's trying to modify based on the specified path within the playbook. This often happens if a typo exists in the path or the files have been moved since the playbook was last created. It's unlikely she's experiencing network instability, user configuration issues, or syntax errors without more context.
11 / 15
David in the code review is pointing out this comment: 'This Ansible task uses `apt update && apt install` – it will repeatedly try to upgrade packages every time the playbook runs, even if they're already up-to-date. This isn't idempotent and could cause issues.' What does David mean by 'idempotency' in this context?
Idempotency is a core concept in Ansible and DevOps. It means a playbook task should produce the same outcome regardless of how many times it's executed – essentially, it should leave the system in its desired state without making unnecessary changes. David's comment highlights the problem with using commands like `apt update && apt install` which will always attempt to upgrade packages, even if they are already up-to-date, violating this principle.
12 / 15
You're writing a PR description for an Ansible playbook that installs and configures a web server. The PR includes the following section: 'This playbook uses variables defined in the defaults/main.yml file to customize the web server settings.' What is the primary benefit of using variables stored in a file like defaults/main.yml?
Using variables in a file like defaults/main.yml promotes reusability and flexibility. This approach allows you to easily adapt the playbook for different environments by simply modifying the values within that file – without needing to change the core logic of the playbook itself. This is crucial for managing configurations across various stages of deployment.
13 / 15
You've been asked to create an Ansible playbook that manages the deployment of a database server. The inventory file defines the following group: [databases] db01.example.com. What does this line in the inventory file represent?
This line specifies the *hostname* and *IP address* of the database server (db01.example.com) that Ansible will manage. The inventory file is used to define the servers that Ansible interacts with; this particular entry tells Ansible which server it's targeting for configuration management.
14 / 15
During a daily standup meeting, your team lead asks: 'Can you explain what the `changed=5` line in this Ansible playbook summary means?' The summary reads: PLAY RECAP: webserver01 : ok=8 changed=5 unreachable=0 failed=1 skipped=2 rescued=0. What is the most accurate interpretation of this value?
The `changed=5` value in an Ansible playbook summary indicates that five tasks within the playbook executed and made modifications to the target system. Unlike `ok`, which means the task completed without error, `changed` specifically highlights when a configuration item was altered as part of the task's execution. This is key for understanding what the playbook *did* during its run.
15 / 15
You're reviewing a colleague's Slack message: 'I'm trying to install `nginx` on our webservers using Ansible, but the task is failing with 'Permission denied'. I've checked the user and file permissions, and they seem correct. Any ideas?' Considering Ansible's role in system administration, what is the MOST likely root cause of this issue?
While several factors could contribute to a 'Permission denied' error in Ansible, the most common and likely cause is insufficient sudo privileges. The `apt install` command requires elevated permissions to modify system packages. The other options are less directly related to this specific error message; DNS issues would affect connectivity, incorrect user variables would lead to authentication problems, and network unreachability would prevent any task from executing.
What will I practise in "Ansible Playbook Language Exercises"?
Practice English for Ansible automation: playbook recap output, handler vocabulary, idempotency, inventory group variables, and Ansible role design terminology for DevOps and infrastructure engineers.
How many exercises are in this module?
This module has 15 multiple-choice exercises, each with instant feedback and a full explanation of the correct answer.
Is this exercise free to use?
Yes. Every exercise on CoderSlingo, including this one, is free to use with no account, sign-up, or paywall.
Do I need to create an account to do these exercises?
No account is required. Just click an option to answer — your score for this session is tracked automatically in the progress bar above.
What happens if I choose the wrong answer?
You'll immediately see which answer was correct, plus a full explanation covering the vocabulary and reasoning behind it — mistakes are where most of the learning happens.
Can I retry the exercises if I want a higher score?
Yes — use the "Try again" button on the results screen to reset and go through all the questions again.
Is my progress saved if I close the page?
No. Progress is tracked only for your current visit; reloading or leaving the page resets the counter. This keeps the exercise simple and account-free.
Where can I find more Infrastructure as Code exercises?
Browse the full Infrastructure as Code hub for related drills, or check the "Next up" link below to continue with a connected topic.
How is this different from reading an article on the same topic?
Articles explain vocabulary and concepts in prose; this exercise tests and reinforces that vocabulary through active recall with immediate feedback — the two work best together.
Who writes these exercises?
Every exercise is written by the CoderSlingo team, drawing on real workplace English used in IT roles, then reviewed for accuracy and clarity.