Courseiva

EX294 Transform data with filters and plugins Practice Question

A playbook needs to set a fact 'total_memory' by summing the 'memory_mb' values from a list of servers. Which filter should be used?

⚠ Common exam trap

Test-takers frequently confuse the `map` filter's `attribute` parameter with a direct filter name argument, leading them to choose option B, or they incorrectly assume `sum` can accept an `attribute` parameter like some other filters do.

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

✓

{{ servers | map(attribute='memory_mb') | sum }}

It uses the `map` filter with the `attribute` parameter to extract the `memory_mb` value from each dictionary in the list, then pipes the resulting list of integers into the `sum` filter to compute the total. This is the standard Ansible idiom for summing a specific attribute across a list of dictionaries.

Answer analysis

Option-by-option breakdown

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

  • ✓

    {{ servers | map(attribute='memory_mb') | sum }}

    Why this is correct

    The `map` filter extracts the `memory_mb` attribute from each server dictionary, producing a list of integers, which `sum` then totals into `total_memory`. This satisfies the stem's requirement to aggregate values across a list without a loop, using Jinja2 filters natively supported in Ansible playbooks.

  • ✗

    {{ servers | map('memory_mb') | sum }}

    Why it's wrong here

    The map filter extracts the memory_mb attribute into a list, but sum then receives strings or fails on the resulting sequence without a numeric conversion, so the fact is not set. map is for projecting one attribute across a list, as when building a list of hostnames for later iteration.

  • ✗

    {{ servers | sum }}

    Why it's wrong here

    The sum filter adds numeric values, but servers is a list of dictionaries, so it raises an error instead of extracting memory_mb. It is tempting because sum is the obvious aggregate for a list of numbers, and would be correct if the playbook first mapped the attribute, e.g. servers | map(attribute='memory_mb') | sum.

  • ✗

    {{ servers | sum(attribute='memory_mb') }}

    Why it's wrong here

    The sum filter accepts attribute only when the input is a list of dictionaries and the attribute names a numeric key; here memory_mb is nested inside each server dictionary, so the lookup returns nothing. sum(attribute=...) suits flat dictionaries, not nested structures.

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.