nerdexam
Cisco

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.

Infrastructure Automation

Question

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 expression is used to print the output of the command without its header row?

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)
  • A
    2% (1)
  • B
    8% (5)
  • C
    86% (56)
  • D
    5% (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.

Ashow_ip_int_brief["stdout_lines"][0]

`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.

Bshow_ip_int_brief["stdout_lines"][1:]

`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.

Cshow_ip_int_brief["stdout_lines"][0][:4]Correct

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.

Dshow_ip_int_brief["stdout_lines"]

`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

#Ansible#Output Parsing#String Slicing#Jinja2

Community Discussion

No community discussion yet for this question.

Full 300-910 Practice