servers/templates/ansible.intf.j2

32 lines
901 B
Plaintext
Raw Permalink Normal View History

{% for vrf in interfaces | selectattr('vrf') | map(attribute='vrf.name') | sort | unique %}
auto {{ vrf }}
iface {{ vrf }}
vrf-table auto
address 127.0.0.1/8
address ::1/128
{%+ endfor %}
{%- for iface in interfaces | selectattr('enabled') %}
{% if iface.mgmt_only is not defined or not iface.mgmt_only %}
auto {{ iface.name }}
iface {{ iface.name }}{% if iface.name == 'lo' %} inet loopback{% endif +%}
{% if iface.mtu %}
mtu {{ iface.mtu }}
{% endif %}
{% if iface.vrf %}
vrf {{ iface.vrf.name }}
{% endif %}
{% for ip in iface.ip_addresses %}
address {{ ip.address }}
{% set subnet = ip.address | ipaddr('subnet') %}
{% set prefix = prefixes | selectattr('prefix', '==', subnet) | first %}
{% set gateway = prefix.custom_fields.gateway.address %}
{% if gateway is defined %}
gateway {{ gateway | ipaddr('address') }}
{% endif %}
{% endfor %}
{% endif %}
{% endfor %}