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?
Trap 1: {{ output | lines | first }}
There is no 'lines' filter in Ansible.
Trap 2: {{ output | first }}
The 'first' filter acts on a list, not a string directly.
Trap 3: {{ output | head(1) }}
There is no 'head' filter in Ansible.
- A
{{ output | lines | first }}
Why it fails: There is no 'lines' filter in Ansible.
- B
{{ output | split(' ') | first }}
Splitting on the newline character produces a list of lines, and `first` retrieves index zero, satisfying the requirement to extract only the initial line. Unlike `regex_replace`, which returns a string, this chain yields the isolated first line directly, though `splitlines` handles trailing newlines more robustly.
- C
{{ output | first }}
Why it fails: The 'first' filter acts on a list, not a string directly.
- D
{{ output | head(1) }}
Why it fails: There is no 'head' filter in Ansible.