EX294 Implement advanced Ansible automation Practice Question
An administrator is writing a playbook that must execute a task only when a file exists on the remote host. They use the `stat` module to check the file and register the result. Which conditional expression should be used to run a subsequent task based on the file's existence?
⚠ Common exam trap
The trap here is forgetting that the `stat` module nests its results under a `stat` key; many mistakenly use `stat_result.exists` directly.
Answer choices
Why each option matters
Answer the question above first, then reveal the full breakdown to understand why each option is right or wrong.
Correct answer & explanation
✓
`when: stat_result.stat.exists`
The `stat` module returns a dictionary where the `stat` key contains the file status information. The correct way to check if the file exists is to reference `stat_result.stat.exists`. This ensures the conditional evaluates correctly based on the module's output.
Answer analysis
Option-by-option breakdown
For each option: why learners choose it and why it is or isn't the right answer here.
- ✗
`when: stat_result.exists`
Why it's wrong here
The `stat` module returns a dictionary with keys like `exists`, `isreg`, etc. However, the registered variable is a dictionary that includes a `stat` key containing the actual result. The correct reference is `stat_result.stat.exists`, not `stat_result.exists`. Using `stat_result.exists` would fail because that key does not exist at the top level.
- ✗
`when: stat_result.stat.is_exists`
Why it's wrong here
While the `stat` module returns a `stat` dictionary, the key for existence is `exists`, not `is_exists`. Using `is_exists` would cause the condition to fail because that key does not exist. This is a common typo or misunderstanding of the returned data structure.
- ✗
`when: stat_result.is_exists`
Why it's wrong here
There is no key named `is_exists` in the result of the `stat` module. The correct key is `exists` within the `stat` dictionary. Using `is_exists` would result in an undefined variable error, and the task would fail or be skipped incorrectly.
- ✓
`when: stat_result.stat.exists`
Why this is correct
The `stat` module registers a variable that contains a `stat` key, which is a dictionary with keys such as `exists`, `isreg`, etc. Therefore, the correct conditional to check if the file exists is `stat_result.stat.exists`. This is the standard way to use the result of the `stat` module.
Go deeper
Related to this question
About these practice questions
Courseiva writes every EX294 question from scratch — 392 in total, each with an explanation and a wrong-answer breakdown. None are copied from real exams or dumps. Learn why practice questions differ from exam dumps →
JA
Written and reviewed by Johnson Ajibi, MSc IT Security
Senior Network & Security Engineer · founder of Courseiva
Last reviewed September 2026 · checked against the official Red Hat exam blueprint
This EX294 practice question is part of Courseiva's free Red Hat certification practice question bank. Courseiva provides original exam-style practice questions with explanations, topic-based practice, mock exams, readiness tracking, and study analytics to help learners prepare for the EX294 exam.