EX294 • Practice Test 38
Free EX294 practice test — 15 questions with explanations. Set 38. No signup required.
An Ansible playbook is used to generate configuration files for network devices. The variables are defined in a vars file like: ---
interfaces:- name: GigabitEthernet1 ip: 192.168.1.1/24 - name: GigabitEthernet2 ip: 10.0.0.1/24
The playbook uses a Jinja2 template to render the config. The template iterates over interfaces and writes "ip address" lines. However, the designer wants to support an additional field "secondary_ips" which is a list of IP addresses (e.g., ["192.168.2.1/24", "192.168.3.1/24"]). In the template, they want to generate multiple "ip address" lines for each interface, one for the primary IP and one for each secondary IP. The following template fragment is used:
{% for iface in interfaces %}
interface {{ iface.name }}
ip address {{ iface.ip }}
{% for sec in iface.secondary_ips|default([]) %}
ip address {{ sec }}
{% endfor %}
{% endfor %}This works when secondary_ips is defined. However, some interfaces have secondary_ips defined as a string (e.g., "192.168.2.1/24") instead of a list. The playbook fails because the inner loop tries to iterate over a string. The engineer wants to normalize the data in the playbook before passing to the template, so that secondary_ips is always a list. Which of the following set_fact tasks will correctly transform the interfaces list to ensure secondary_ips is always a list (even if missing or a string)?
Choose an answer to begin — your selection is scored in the full session.
15 questions · instant feedback and full explanations after every question.