Courseiva

EX294 Manage task execution and roles Practice Question

An administrator maintains a role named 'webserver' that is used by several teams. The role must run a handler named 'restart httpd' after a configuration file is changed, but only when the role is included with a variable 'notify_handler' set to true. The role's tasks/main.yml currently has a task that copies httpd.conf with 'notify: restart httpd'. Which change should the administrator make in the role to ensure the handler is notified only when 'notify_handler' is true?

⚠ Common exam trap

The trap here is assuming that a 'when' condition on a handler prevents the handler from being notified, when in fact it only controls whether the handler runs after being queued.

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

✓

Add 'when: notify_handler | bool' to the task that copies httpd.conf in tasks/main.yml.

The handler is notified only when a task reports a change. To make notification conditional, the condition must be applied to the task that performs the change and notifies the handler. Adding a 'when' clause to the copy task ensures the task runs only when 'notify_handler' is true, so the handler is queued only in that case. Conditions on handlers themselves do not prevent notification from being queued.

Answer analysis

Option-by-option breakdown

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

  • ✗

    Add 'run_once: true' to the handler and set 'notify_handler' in the role's defaults/main.yml.

    Why it's wrong here

    'run_once' controls how many hosts execute the handler, not whether it is notified. Setting a default value for 'notify_handler' does not make the notification conditional; the task would still notify the handler regardless of the variable's value at runtime. This combination does not meet the requirement and would cause the handler to be notified even when the variable is false.

  • ✗

    Add 'listen: "{{ notify_handler }}"' to the handler and notify the handler with 'notify: "{{ notify_handler }}"'.

    Why it's wrong here

    'listen' is used to allow a handler to be notified by a topic name, and it does not accept a boolean condition. Using a variable that evaluates to true or false as a listen topic would create a topic named 'True' or 'False', not conditionally suppress notification. This approach misuses the listen feature and does not provide a reliable conditional notification mechanism.

  • ✗

    Add 'when: notify_handler | bool' to the handler definition in handlers/main.yml.

    Why it's wrong here

    Handlers support 'when' conditions, but the condition is evaluated when the handler is notified or runs, not when the notifying task executes. If the task always notifies the handler, the handler will be queued and then skipped at handler-run time if the condition is false. This does not prevent the notification from being queued, and it does not satisfy the requirement that the handler be notified only when the variable is true. The condition belongs on the task that notifies the handler.

  • ✓

    Add 'when: notify_handler | bool' to the task that copies httpd.conf in tasks/main.yml.

    Why this is correct

    Placing the conditional on the task that copies the configuration file ensures the task only runs when 'notify_handler' is true. Because notification occurs only when a task reports 'changed', the handler will be notified only if the copy task actually executes and changes the file. This directly meets the requirement and is the standard Ansible pattern for conditionally notifying handlers from within a role.

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 →

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.