Courseiva

EX294 Transform data with filters and plugins Practice Question

A playbook needs to generate a default value for a variable if it is undefined or empty. Which filter with a default value should be used?

⚠ Common exam trap

Red Hat often tests the distinction between filters that handle undefined variables (`default`) versus filters that perform conditional logic (`ternary`) or error handling (`fail`), and the trap here is that candidates may confuse `coalesce` (a common SQL function) with a valid Ansible filter, leading them to select option D.

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

✓

my_var | default('fallback')

The `default` filter in Ansible is specifically designed to provide a fallback value when a variable is undefined or evaluates to an empty string (with the `omit` parameter). It is the idiomatic way to handle missing or empty variables in Jinja2 templates within Ansible playbooks, ensuring idempotency and avoiding undefined variable errors.

Answer analysis

Option-by-option breakdown

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

  • ✗

    my_var | fail('fallback')

    Why it's wrong here

    fail filter makes the task fail with a message.

  • ✗

    my_var | ternary('fallback', my_var)

    Why it's wrong here

    ternary is used for if-else conditions, not for default.

  • ✓

    my_var | default('fallback')

    Why this is correct

    default filter returns 'fallback' if my_var is undefined.

  • ✗

    my_var | coalesce('fallback')

    Why it's wrong here

    coalesce returns first non-null argument, but if my_var is undefined it raises an error.

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.