EX294 Transform data with filters and plugins Practice Question
A playbook reads a YAML file containing a list of dictionaries named `packages`, where each dictionary has keys `name`, `version`, and `enabled`. You need to produce a comma-separated string of only the `name` values for all entries where `enabled` is true. Which Jinja2 expression accomplishes this in a single task variable assignment?
⚠ Common exam trap
The trap here is assuming that `map` and `selectattr` can be used in any order, when in fact `map` transforms the data structure and must come after attribute-based filtering.
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
✓
{{ packages | selectattr('enabled') | map(attribute='name') | join(',') }}
Filtering a list of dictionaries by a boolean attribute and then extracting a specific key is a common data transformation. The `selectattr` filter is designed to filter by attribute, `map(attribute=...)` extracts the desired key, and `join` combines the results into a string. The order of operations is critical: filter first, then map, then join.
Answer analysis
Option-by-option breakdown
For each option: why learners choose it and why it is or isn't the right answer here.
- ✗
{{ packages | json_query('[?enabled].name') | join(',') }}
Why it's wrong here
`json_query` uses JMESPath syntax, not Jinja2 expression syntax, and requires the `community.general` collection to be installed. The expression `[?enabled].name` is not valid JMESPath; the correct JMESPath would be `[?enabled].name` only after proper quoting and would still return a list rather than a filtered string. This adds a dependency and is unnecessary here.
- ✗
{{ packages | select('enabled') | map(attribute='name') | join(',') }}
Why it's wrong here
The `select` filter tests the values themselves, not a named attribute of each dictionary. Since each element is a dictionary rather than a string, `select('enabled')` does not evaluate the `enabled` key inside the dictionary and produces the wrong result. You need `selectattr` for attribute-based filtering.
- ✓
{{ packages | selectattr('enabled') | map(attribute='name') | join(',') }}
Why this is correct
The `selectattr` filter keeps only items whose `enabled` attribute is truthy, then `map(attribute='name')` extracts the name from each remaining dictionary, and `join(',')` collapses the resulting list into a comma-separated string. This matches the requirement exactly without needing a loop or extra variable.
- ✗
{{ packages | map(attribute='name') | selectattr('enabled') | join(',') }}
Why it's wrong here
Here `map` runs first and converts the list of dictionaries into a list of strings, so the subsequent `selectattr('enabled')` tries to read an `enabled` attribute from a string and fails or returns nothing. Order matters: you must filter the dictionaries before extracting the name attribute.
Go deeper
Related to this question
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 →
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.