Courseiva

EX294 Manage task execution and roles Practice Question

An administrator is writing a role where a task should only execute when the variable `web_package` is defined and its value is `httpd`. The role must not fail if the variable is undefined. Which task condition is correct?

⚠ Common exam trap

The trap here is assuming that a simple equality check or a default filter safely handles undefined variables, but only the defined test with and short-circuits to prevent errors.

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

✓

when: web_package is defined and web_package == "httpd"

The task must run only when web_package is defined and its value is httpd, without failing if undefined. The condition using 'is defined' followed by 'and' correctly short-circuits so that the variable is only compared when it exists. The other conditions either fail on undefined variables, run when the variable is missing, or use incorrect logic.

Answer analysis

Option-by-option breakdown

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

  • ✓

    when: web_package is defined and web_package == "httpd"

    Why this is correct

    This condition first checks if the variable is defined, short-circuiting safely if it is not, then compares its value. Because Ansible evaluates conditions with Jinja2 and short-circuiting, referencing an undefined variable in the second part is avoided. This meets the requirement of not failing when the variable is missing and only running when the value is exactly httpd.

  • ✗

    when: web_package == "httpd"

    Why it's wrong here

    If web_package is undefined, this condition raises an error during templating, causing the task to fail rather than skip. The scenario explicitly requires that the task not fail when the variable is undefined. A simple equality check does not guard against undefined variables, so this option is incorrect.

  • ✗

    when: web_package | default("httpd") == "httpd"

    Why it's wrong here

    This condition would run the task even when web_package is undefined, because the default filter substitutes 'httpd' and the equality becomes true. The requirement is to run only when the variable is defined and equals httpd. Although it avoids failure, it changes the behavior by running when the variable is absent, so it is wrong.

  • ✗

    when: web_package is defined or web_package == "httpd"

    Why it's wrong here

    Using 'or' means the condition is true if web_package is defined even if its value is not httpd, or if it is undefined but equals httpd (which would error). It does not enforce the required equality and can run the task incorrectly. The logic is flawed for the requirement and may still fail on undefined variables.

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 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.