Courseiva

EX294 Transform data with filters and plugins Practice Question

A playbook reads a YAML configuration file with the `include_vars` module and registers the result. The variable `app_config` now holds a dictionary with keys `database`, `cache`, and `logging`. You need to produce a list containing only the top-level key names for a later loop. Which Jinja2 filter expression should you use in the task that builds this list?

⚠ Common exam trap

It's easy for candidates to confuse `dict2items` with `items2dict` and assuming either one works in both directions on a dictionary.

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

✓

{{ app_config | dict2items | map(attribute='key') | list }}

To turn dictionary keys into a list, the canonical approach is to convert the dictionary to a list of `{key, value}` dictionaries with `dict2items`, then extract the `key` attribute using `map`. The resulting list can be looped over directly. Filters like `items2dict`, `flatten`, and `subelements` operate on different data shapes and do not produce top-level key names from a plain dictionary.

Answer analysis

Option-by-option breakdown

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

  • ✗

    {{ app_config | items2dict | map(attribute='key') | list }}

    Why it's wrong here

    `items2dict` performs the opposite transformation: it takes a list of key/value dictionaries and builds a dictionary. Since `app_config` is already a dictionary, `items2dict` fails because it expects a list input. Even if it succeeded, the subsequent `map` would not yield the intended top-level keys for this scenario.

  • ✓

    {{ app_config | dict2items | map(attribute='key') | list }}

    Why this is correct

    The `dict2items` filter converts a dictionary into a list of dictionaries, each with a `key` and `value` field. Applying `map(attribute='key')` extracts the original top-level dictionary keys, and `list` materializes the result. This produces exactly the list of top-level names required for the loop, without touching nested values.

  • ✗

    {{ app_config | flatten | map(attribute='key') | list }}

    Why it's wrong here

    `flatten` is designed for nested lists, not dictionaries. Applied to a dictionary it does not produce a list of key/value items, so the following `map(attribute='key')` has nothing valid to traverse. This expression will error or return an unexpected structure, failing to yield the top-level key names.

  • ✗

    {{ app_config | subelements('key') | map(attribute='key') | list }}

    Why it's wrong here

    `subelements` expects a list of dictionaries and a key whose value is itself a list, producing a cross-product. A plain dictionary is not a valid input, and the `key` attribute here is not a list of nested items. This filter is the wrong tool for extracting top-level dictionary keys.

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.