Courseiva

EX294 Transform data with filters and plugins Practice Question

An Ansible task uses the variable `{{ my_var | default(required=true) }}`. What happens if `my_var` is undefined?

⚠ Common exam trap

Many candidates confuse `default(required=true)` with setting a default value, thinking it will use the string 'required' or an empty string, when in fact it enforces mandatory variable definition and causes a failure.

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

✓

The task fails with an error message

The `default(required=true)` filter in Ansible explicitly marks the variable as required. If `my_var` is undefined, the filter raises an error because it enforces that the variable must be provided, causing the task to fail with an error message. This is a deliberate mechanism to catch missing mandatory variables early in playbook execution.

Answer analysis

Option-by-option breakdown

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

  • ✓

    The task fails with an error message

    Why this is correct

    The `default` filter with `required=true` raises an undefined-variable error when `my_var` is absent, halting the task immediately. This satisfies the stem's constraint that an undefined variable must not silently fall back to a substitute value, unlike a plain `default('x')` which would return the fallback instead.

  • ✗

    The task skips the host

    Why it's wrong here

    The default filter with required=true raises an undefined-variable error, failing the task on that host rather than skipping it. Skipping is tempting because Ansible does skip hosts on unreachable or failed conditions, but an undefined mandatory variable aborts the play for that host instead.

  • ✗

    The task uses an empty string

    Why it's wrong here

    Supplying an empty string is what default() does without required=true, but required=true forces an error when the variable is undefined. The empty-string behaviour is tempting because it is the filter's normal fallback, yet the mandatory flag changes the outcome to a fatal undefined-variable failure.

  • ✗

    The task uses the string 'required'

    Why it's wrong here

    The string 'required' is never substituted; required=true is a keyword argument that makes the filter raise an error on an undefined variable. Treating it as a literal value is tempting because default() normally returns its argument, but here the argument configures error behaviour instead.

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