Courseiva

EX294 Transform data with filters and plugins Practice Question

An administrator must parse an inventory file where hostnames are stored in YAML format under a list 'nodes'. The task needs to extract only hostnames that contain 'prod' in the name, then sort them in reverse order. Which combination of filters in a single Ansible expression achieves this?

⚠ Common exam trap

Watch out — candidates often confuse `select` (which keeps matching items) with `reject` (which removes matching items), or mistakenly use `regex_search` or `map` thinking they will filter the list, when in fact those filters return substrings or transformed values, not the original list elements.

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

✓

nodes | select('match', '.*prod.*') | sort(reverse=True)

The `select` filter with the `match` test returns only list items that match the regex `'.*prod.*'`, i.e., hostnames containing 'prod'. The `sort(reverse=True)` then sorts the resulting list in descending alphabetical order, fulfilling both requirements in a single Ansible expression.

Answer analysis

Option-by-option breakdown

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

  • ✓

    nodes | select('match', '.*prod.*') | sort(reverse=True)

    Why this is correct

    The select filter with match applies the regex '.*prod.*' to each node, keeping only hostnames containing prod, and sort(reverse=True) orders the survivors descending. This single chained expression satisfies both the filtering and reverse-sorting constraints in one evaluation.

  • ✗

    nodes | regex_search('prod') | sort(True)

    Why it's wrong here

    regex_search returns the matched substring or None, not a filtered list, so sort receives a string or null and fails. It is tempting because regex_search detects the pattern, but selecting matching elements requires select with match or selectattr, then sort(reverse=True).

  • ✗

    nodes | map('regex_search', 'prod') | sort(reverse=True)

    Why it's wrong here

    map applies regex_search to every element, yielding matches or None rather than the hostnames themselves, so the filtered list is wrong. It is tempting because map transforms lists, but the task needs select to retain matching hostnames before reverse sorting.

  • ✗

    nodes | reject('match', '.*prod.*') | sort(reverse=True)

    Why it's wrong here

    The reject filter removes every hostname matching '.*prod.*', leaving exactly the non-production hosts — the inverse of what is required. It is tempting because reject is the natural filter for excluding entries, and it would be correct if the task were to discard production nodes rather than keep them.

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