ansible-role-systemd_networkd/templates/systemd-network.j2
Dmitriy Rabotyagov 12a0da6ab8 Don't make VLAN/VXLAN/MACVLAN mutually exclusive
Each interface can have multiple VLAN/VXLAN/MACVLAN at the same
time and these options are not mutually exclusive.

They are mutually exclusive though with Bridge/Bond options, as not
applicable when interface is part of the bridge or bond.

Change-Id: Ife417a4ec72b561f68bc60f5d5b179b82524ae7a
2024-09-14 12:30:11 +02:00

68 lines
1.8 KiB
Django/Jinja

# {{ ansible_managed }}
[Match]
Name={{ item.1.interface }}
{% if item.1.address is defined and (item.1.address | lower) == 'dhcp' %}
[DHCP]
UseDNS={{ (item.1.usedns | default(false) | bool) | ternary('yes', 'no') }}
UseNTP=yes
RouteMetric=20
{% endif %}
{%- if item.1.address is not defined %}
{# Address is not defined #}
{% set _addresses = [] %}
{% elif item.1.address is iterable and item.1.address is not string %}
{# Address is a list, multiple addresses defined #}
{% set _addresses = item.1.address %}
{% else %}
{# Single address defined #}
{% set _addresses = [item.1] %}
{% endif %}
[Network]
{% for _addr in _addresses %}
{% if _addr is string %}
{% set _addr = {'address': _addr} %}
{% endif %}
{% if _addr.address == 'dhcp' %}
DHCP=yes
{% else %}
{% set _addr_cidr = (_addr.address ~ '/' ~ _addr.netmask | default('')).rstrip('/') | ansible.utils.ipaddr('host') %}
Address={{ _addr_cidr }}
{% endif %}
{% if _addr.gateway is defined and (_addr.gateway | length) > 0 %}
Gateway={{ item.1.gateway }}
{% endif %}
{% endfor %}
{% if item.1.bridge is defined %}
Bridge={{ item.1.bridge }}
{% elif item.1.bond is defined %}
Bond={{ item.1.bond }}
{% else %}
{% if item.1.vlan is defined %}
{% if item.1.vlan is iterable and item.1.vlan is not string %}
{% for vlan in item.1.vlan %}
VLAN={{ vlan }}
{% endfor %}
{% else %}
VLAN={{ item.1.vlan }}
{% endif %}
{% endif %}
{% if item.1.macvlan is defined %}
MACVLAN={{ item.1.macvlan }}
{% endif %}
{% if item.1.vxlan is defined %}
VXLAN={{ item.1.vxlan }}
{% endif %}
{% endif %}
{% if item.1.ipforward is defined %}
IPForward={{ (item.1.ipforward | bool) | ternary('yes', 'no') }}
{% endif %}
[Link]
{% if item.1.mtu is defined and item.1.mtu %}
MTUBytes={{ item.1.mtu }}
{% endif %}