{% if N_HOP == "name" -%}
ip route vrf Primark 165.225.194.0 255.255.254.0 {{ OUT_INT }} name Zscaler_Copenhagen_II track 1
{%- else %}
ip route vrf Primark 165.225.194.0 255.255.254.0 {{ OUT_INT }} {{ N_HOP }} name Zscaler_Copenhagen_II track 1
{%- endif %}
!
!
{% if loop.index is divisibleby 3 %}
{% endif %}
第二个loop需要使用方括号[]来调用diction key, 不能使用{} 在大括号中,否则会报错。
"msg": "AnsibleError: template error while templating string: expected name or number.
{% for interf in ansible_net_interfaces.keys()|sort %}
{% if "bridged" in ansible_net_interfaces[interf].type and ansible_net_interfaces[interf].lineprotocol == "up" %}
interface {{interf}}
description ** Change from ansible **
no switchport
{% else %}
interface {{interf}}
description ** No change **
{% endif %}
{% endfor %}