Courseiva

EX294 Manage task execution and roles Practice Question

An administrator needs to execute a role named `common` on all hosts in the play, but only for hosts that are members of the `webservers` group. Which playbook construct achieves this?

⚠ Common exam trap

The trap here is overcomplicating host targeting with conditions or variables when the play's hosts directive is the correct and simplest mechanism.

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

✓

Apply the role under a play with hosts: webservers.

The most direct way to run a role only on a specific group is to target that group in the play's hosts directive. Roles run on all hosts in the play, so restricting the play's hosts restricts the role. Other options either do not filter hosts or misuse Ansible features.

Answer analysis

Option-by-option breakdown

For each option: why learners choose it and why it is or isn't the right answer here.

  • ✓

    Apply the role under a play with hosts: webservers.

    Why this is correct

    Defining the play with hosts: webservers ensures the role only runs on hosts in that group. Roles applied in a play are executed on all hosts targeted by the play. This is the standard and simplest way to restrict role execution to a specific host group.

  • ✗

    Add a task with delegate_to: webservers before including the role.

    Why it's wrong here

    delegate_to is used to run a task on a different host, not to filter hosts for a role. It does not prevent the role from running on other hosts. This option is incorrect and misuses delegation.

  • ✗

    Set a variable in group_vars/webservers.yml and use it in the role's tasks.

    Why it's wrong here

    Variables alone do not restrict which hosts run the role; they only provide data. The role would still execute on all hosts in the play. This option does not limit execution to the webservers group, so it fails the requirement.

  • ✗

    Use the roles keyword with a when condition on the group name.

    Why it's wrong here

    The roles keyword does not directly support a when condition; conditions are applied to tasks inside the role or via include_role. Even if possible, it is more complex and not the intended method. The scenario asks for a playbook construct, and targeting hosts is the correct approach.

About these practice questions

One of 392 original EX294 practice questions on Courseiva, each with a full explanation and wrong-answer analysis — not exam dumps or protected exam content. Learn why practice questions differ from exam dumps →

How Courseiva writes practice questions · Editorial policy

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.