Courseiva

EX294 Manage task execution and roles Practice Question

An administrator wants to ensure a role's tasks are executed only on certain hosts. Which approach should they use?

⚠ Common exam trap

It's easy for candidates to confuse variable scoping (host_vars/group_vars) with conditional execution, assuming that setting variables for a host or group inherently limits task execution to those hosts, when in fact variables only provide data and do not control task flow without an explicit 'when' condition.

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 a 'when' condition in the role's tasks

Ansible's 'when' clause allows conditional execution of tasks based on variables such as inventory hostname, group membership, or custom facts. By using a 'when' condition that checks the target host's identity (e.g., 'ansible_hostname' or 'inventory_hostname'), the administrator can ensure that the role's tasks run only on specific hosts, without modifying inventory structure or using separate variable files.

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 host_vars for each target host

    Why it's wrong here

    Host variables supply per-host data, not task targeting; roles run wherever the play applies them. Restricting execution requires a conditional in the play or role, such as a when clause on group membership. Host vars would be the right choice for host-specific values like IP addresses or ports.

  • ✗

    Set group_vars for the target group

    Why it's wrong here

    Group variables supply data to hosts in a group; they do not limit which hosts receive the role's tasks. The play still applies the role to every targeted host. Group vars are correct when you need shared values, such as a common database name, across a group.

  • ✓

    Use a 'when' condition in the role's tasks

    Why this is correct

    A 'when' condition evaluates host facts or variables at runtime, so tasks run only where the predicate is true. This satisfies the stem's constraint of restricting a role's tasks to certain hosts, though it filters per task rather than limiting which hosts the role targets.

  • ✗

    Use tags on the role

    Why it's wrong here

    Tags applied to a role restrict which tasks within it run, not which hosts execute the role. It is tempting because tags control task selection, but host targeting requires the role's play to specify hosts or a host pattern in the playbook.

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 →

How Courseiva writes practice questions · Editorial policy

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.