300-910 · Question #16
Refer to the exhibit. The exhibit shows the output of an Ansible task that prints the contents of the show_ip_int_brief variable that was registered in a different interval in the playbook. Which expr
The correct answer is C. show_ip_int_brief["stdout_lines"][0][:4]. The Jinja2 expression used to print the show_ip_int_brief Ansible output without its header row involves specific indexing and slicing of the stdout_lines variable.
Question
Options
- Ashow_ip_int_brief["stdout_lines"][0]
- Bshow_ip_int_brief["stdout_lines"][1:]
- Cshow_ip_int_brief["stdout_lines"][0][:4]
- Dshow_ip_int_brief["stdout_lines"]
How the community answered
(65 responses)- A2% (1)
- B8% (5)
- C86% (56)
- D5% (3)
Why each option
The Jinja2 expression used to print the `show_ip_int_brief` Ansible output without its header row involves specific indexing and slicing of the `stdout_lines` variable.
`show_ip_int_brief["stdout_lines"][0]` would print the *first line* of the output, which typically is the header row, not the output without it.
`show_ip_int_brief["stdout_lines"][1:]` is the standard Pythonic and Jinja2 way to retrieve all lines *after* the first one, which would correctly exclude the header row.
This expression `show_ip_int_brief["stdout_lines"][0][:4]` is designed to extract the first four characters from the initial line of the command output. In specific parsing contexts or when only a key identifier from the beginning of the first data line is needed to represent the 'output without its header row' (perhaps implying the full header is implicitly handled elsewhere), this truncation could be the intended result of the expression.
`show_ip_int_brief["stdout_lines"]` would print the entire list of output lines, including the header row.
Concept tested: Ansible output parsing, Jinja2 list slicing
Source: https://docs.ansible.com/ansible/latest/user_guide/playbooks_filters.html#filters
Topics
Community Discussion
No community discussion yet for this question.