EX294 Manage task execution and roles Practice Question
A systems administrator needs to run a playbook that installs packages on a group of managed nodes. The playbook should run only on nodes that are part of the 'web_servers' group in the inventory. Which approach is best practice?
⚠ Common exam trap
The trap here is that candidates may overcomplicate the solution by choosing runtime flags or conditional logic, forgetting that Ansible's simplest and most explicit targeting method—setting 'hosts' to the group name—is both best practice and the most reliable for clarity and execution.
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
✓
Set 'hosts: web_servers' in the play.
Setting 'hosts: web_servers' in the play directly targets only the nodes in that inventory group, which is the simplest and most maintainable approach. This follows Ansible's best practice of declaring the target group explicitly in the playbook rather than relying on runtime flags or conditional logic, ensuring the playbook's intent is clear and portable.
Answer analysis
Option-by-option breakdown
For each option: why learners choose it and why it is or isn't the right answer here.
- ✓
Set 'hosts: web_servers' in the play.
Why this is correct
Setting `hosts: web_servers` scopes the play directly to the inventory group, so Ansible targets only those managed nodes and skips all others. This satisfies the constraint that execution must be limited to the 'web_servers' group, using Ansible's native group pattern matching rather than conditional logic or delegation.
- ✗
Set 'hosts: all' and use '--limit web_servers' when running ansible-playbook.
Why it's wrong here
Using hosts: all with --limit works only when the operator remembers the flag; the playbook itself then targets every host, so an unqualified run hits unrelated nodes. It tempts because --limit is the standard ad-hoc way to narrow a run without editing the playbook.
- ✗
Set 'hosts: localhost' and delegate tasks to web_servers.
Why it's wrong here
hosts: localhost runs the play on the control node, so package installation executes there unless every task is explicitly delegated; delegation suits tasks needing a specific host, not targeting a managed group. It tempts because localhost plays are common for orchestration and API calls.
- ✗
Set 'hosts: all' and use a 'when' condition to check if the node is in the web_servers group.
Why it's wrong here
A when condition evaluates per host after connection, so Ansible still connects to every node in the inventory and gathers facts, wasting effort and risking unintended changes. It tempts because when is the usual tool for conditional task execution, but host selection belongs in the hosts line.
Go deeper
Related to this question
About these practice questions
This EX294 question is part of Courseiva's 392-question bank — original exam-style content with full explanations and wrong-answer analysis, never real exam questions or exam 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.