Courseiva
Transform data with filters and pluginseasyMultiple ChoiceObjective-mapped

EX294 Transform data with filters and plugins Practice Question

An Ansible playbook needs to extract the first line from a multi-line string variable 'output' and store it in a new variable 'first_line'. Which filter should be used?

⚠ Common exam trap

Many exam-takers confuse the `first` filter's behavior on strings vs. lists, assuming it extracts the first line when it actually extracts the first character.

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

{{ output | split(' ') | first }}

The `split('\n')` filter splits the multi-line string into a list of lines, and the `first` filter extracts the first element. This is the standard Ansible approach to isolate the first line from a string variable.

Answer analysis

Option-by-option breakdown

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

  • {{ output | lines | first }}

    Why it's wrong here

    There is no 'lines' filter in Ansible.

  • {{ output | split(' ') | first }}

    Why this is correct

    Correct: split into lines then take first.

  • {{ output | first }}

    Why it's wrong here

    The 'first' filter acts on a list, not a string directly.

  • {{ output | head(1) }}

    Why it's wrong here

    There is no 'head' filter in Ansible.

About these practice questions

This EX294 question is part of Courseiva's 520-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 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.