EX294 Manage task execution and roles Practice Question
An administrator is designing a role that needs to execute a set of tasks conditionally based on whether a package is installed. Which approach is best practice?
⚠ Common exam trap
Test-takers frequently confuse `ansible_facts.packages` (which is a variable that must be populated by `package_facts`) with a pre-existing fact, leading them to choose option C without realizing the module is required first.
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
✓
Use the package_facts module
The `package_facts` module is the best practice for gathering package installation status in Ansible. It populates the `ansible_facts.packages` variable with structured data about installed packages, allowing you to conditionally execute tasks using `when` statements without relying on external commands or file checks. This approach is idempotent, efficient, and aligns with Ansible's declarative philosophy.
Answer analysis
Option-by-option breakdown
For each option: why learners choose it and why it is or isn't the right answer here.
- ✗
Use the stat module to check package file existence
Why it's wrong here
The stat module inspects filesystem paths, so it cannot report whether an RPM package is registered in the package database; use the package_facts module or dnf/yum checks instead. It is tempting because stat is the standard way to test for a file's existence, which would be correct when a task depends on a config file or binary path rather than a package.
- ✗
Use the command module to check package status
Why it's wrong here
Running a command to check package status executes on every task run and reports failure when the package is absent, breaking idempotence. It is tempting because shell queries work without fact gathering, and would be correct for ad-hoc inspection, but a role condition needs a declarative, repeatable package check.
- ✗
Use ansible_facts.packages
Why it's wrong here
ansible_facts.packages is only populated when the package fact-gathering module has run, so it is empty unless explicitly gathered, making the condition unreliable. It is tempting because it reads installed packages without invoking a shell, and would be correct when facts are gathered first, but the stem requires a dependable check.
- ✓
Use the package_facts module
Why this is correct
package_facts gathers installed package information into the package_facts variable, letting subsequent tasks evaluate conditions against actual system state. This avoids shelling out to rpm or dpkg and keeps the check idempotent and portable across distributions.
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 by Johnson Ajibi, MSc IT Security
Senior Network & Security Engineer · founder of Courseiva
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.