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 wrong: There is no 'lines' filter in Ansible.
- B
{{ output | split(' ') | first }}
Correct: split into lines then take first.
- C
{{ output | first }}
Why wrong: The 'first' filter acts on a list, not a string directly.
- D
{{ output | head(1) }}
Why wrong: There is no 'head' filter in Ansible.