1
0

systemd-networkd templates

This commit is contained in:
michael 2023-08-10 21:29:39 +10:00
parent 5f1e304301
commit 621d9595f8
5 changed files with 154 additions and 41 deletions

View File

@ -11,26 +11,75 @@ systemd_networkd_configs:
- name: 00-eth3.link - name: 00-eth3.link
src: ethernet.link.j2 src: ethernet.link.j2
mac_address: 00-00-00-00-00-00 mac_address: 00-00-00-00-00-00
- name: br0.netdev - name: 01-eth0.network
src: ethernet.network.j2
mac_address: 00-00-00-00-00-00
arp: false
lldp: true
dhcp: false
bridge:
name: br0
vlans:
- 110
- 210
pvid: 210
- name: 01-eth1.network
src: ethernet.network.j2
mac_address: 00-00-00-00-00-00
arp: false
lldp: true
dhcp: false
bridge:
name: br0
vlans:
- 210
pvid: 210
- name: 01-eth2.network
src: ethernet.network.j2
mac_address: 00-00-00-00-00-00
arp: false
lldp: true
dhcp: false
bridge:
name: br0
vlans:
- 30
- 210
- 220
- 230
- name: 01-eth3.network
src: ethernet.network.j2
mac_address: 00-00-00-00-00-00
arp: false
lldp: false
dhcp: false
- name: 10-br0.netdev
src: bridge.netdev.j2 src: bridge.netdev.j2
vlan_filtering: true vlan_filtering: true
stp: true stp: true
- name: br0.network - name: 11-br0.network
src: bridge.network.j2 src: bridge.network.j2
- name: vlan110.netdev arp: false
dhcp: false
lldp: true
vlans:
- 110
- name: 20-vlan110.netdev
src: vlan.netdev.j2 src: vlan.netdev.j2
- name: vlan110.network vlan_id: 110
- name: 21-vlan110.network
src: vlan.network.j2 src: vlan.network.j2
arp: true
lldp: true
dhcp: false
address: address:
ipv4: 10.192.110.1/24 ipv4:
ipv6: - 10.192.110.1/24
gateway: gateway:
ipv4: 10.192.110.254 ipv4: 10.192.110.254
ipv6:
nameserver: nameserver:
ipv4: ipv4:
10.192.110.254 - 10.192.110.254
ipv6:
qemu_bridges: qemu_bridges:
br0 br0

View File

@ -4,6 +4,6 @@ Kind=bridge
[Bridge] [Bridge]
DefaultPVID=none DefaultPVID=none
VLANFiltering={{ item.vlan_filtering }} VLANFiltering={{ item.vlan_filtering | default(false)}}
VLANProtocol=802.1q VLANProtocol=802.1q
STP={{ item.stp }} STP={{ item.stp | default(false) }}

View File

@ -1,11 +1,15 @@
[Match] [Match]
Name={{ item.name | regex_replace('^[0-9]*-', '') | regex_replace('\.netdev', '') }} Name={{ item.name | regex_replace('^[0-9]*-', '') | regex_replace('\.network', '') }}
[Link] [Link]
ARP={{ item.arp | default(false) }} ARP={{ item.arp | default(true) }}
[Network] [Network]
DHCP={{ item.dhcp | default(false) }} DHCP={{ item.dhcp | default(true) }}
LinkLocalAddressing=false LinkLocalAddressing=False
LLDP=true LLDP={{ item.lldp | default(true) }}
{% if item.vlans is defined -%}
{% for vlan in item.vlans -%}
VLAN={{ item.vlan }} VLAN={{ item.vlan }}
{% endfor -%}
{% endif -%}

View File

@ -2,18 +2,72 @@
MACAddress={{ item.mac_address }} MACAddress={{ item.mac_address }}
[Link] [Link]
ARP={{ item.arp }} ARP={{ item.arp | default(true) }}
[Network] [Network]
DHCP={{ item.dhcp | default(true) }} DHCP={{ item.dhcp | default(true) }}
{% if item.bond %} LinkLocalAddressing=False
LLDP={{ item.lldp | default(true) }}
{% if item.nameserver is defined and item.nameserver.ipv4 is defined -%}
{% for nameserver in item.nameserver.ipv4 -%}
DNS={{ nameserver }}
{% endfor -%}
{% endif -%}
{% if item.nameserver is defined and item.nameserver.ipv6 is defined -%}
{% for nameserver in item.nameserver.ipv6 -%}
DNS={{ nameserver }}
{% endfor -%}
{% endif -%}
{% if item.bond is defined -%}
Bond={{ item.bond }} Bond={{ item.bond }}
{% endif %} {% endif -%}
{% if item.bridge %} {% if item.bridge is defined -%}
Bridge={{ item.bridge }} Bridge={{ item.bridge.name }}
{% endif %} {% endif -%}
{% if item.vlans %} {% if item.vlans is defined -%}
{% for vlan in item.vlans %} {% for vlan in item.vlans -%}
VLAN={{ vlan }} VLAN={{ vlan }}
{% endfor %} {% endfor -%}
{% endif %} {% endif -%}
{% if item.address is defined %}
[Address]
{% if item.address.ipv4 is defined -%}
{% for address in item.address.ipv4 -%}
Address={{ address }}
{% endfor -%}
{% endif -%}
{% if item.address.ipv6 is defined -%}
{% for address in item.address.ipv6 -%}
Address={{ address }}
{% endfor -%}
{% endif -%}
{% endif -%}
{% if item.gateway is defined and item.gateway.ipv4 is defined %}
[Route]
Destination=0.0.0.0/0
Gateway={{ item.gateway.ipv4 }}
Scope=global
Protocol=static
Type=unicast
{% endif -%}
{% if item.gateway is defined and item.gateway.ipv6 is defined %}
[Route]
Destination=::/0
Gateway={{ item.gateway.ipv6 }}
Protocol=static
Type=unicast
{% endif -%}
{% if item.bridge is defined and item.bridge.vlans is defined %}
[BridgeVLANs]
{% for vlan in item.bridge.vlans -%}
VLAN={{ vlan }}
{% endfor -%}
{% if item.bridge.pvid is defined -%}
PVID={{ item.bridge.pvid }}
EgressUntagged={{ item.bridge.pvid }}
{% endif -%}
{% endif -%}

View File

@ -1,33 +1,39 @@
[Match] [Match]
Name={{ item.name | regex_replace('^[0-9]*-', '') | regex_replace('\.netdev', '') }} Name={{ item.name | regex_replace('^[0-9]*-', '') | regex_replace('\.network', '') }}
[Link] [Link]
ARP={{ item.arp }} ARP={{ item.arp | default(true) }}
[Network] [Network]
{% if item.nameserver.ipv4 is defined -%} DHCP={{ item.dhcp | default(true) }}
LinkLocalAddressing=False
LLDP={{ item.lldp | default(true) }}
{% if item.nameserver is defined and item.nameserver.ipv4 is defined -%}
{% for nameserver in item.nameserver.ipv4 -%} {% for nameserver in item.nameserver.ipv4 -%}
DNS={{ nameserver }} DNS={{ nameserver }}
{% endfor -%} {% endfor -%}
{% endif -%} {% endif -%}
{% if item.nameserver.ipv6 is defined -%} {% if item.nameserver is defined and item.nameserver.ipv6 is defined -%}
{% for nameserver in item.nameserver.ipv6 -%} {% for nameserver in item.nameserver.ipv6 -%}
DNS={{ nameserver }} DNS={{ nameserver }}
{% endfor -%} {% endfor -%}
{% endif -%} {% endif -%}
{% if item.address.ipv4 is defined %} {% if item.address is defined %}
[Address] [Address]
Address={{ item.address.ipv4 }} {% if item.address.ipv4 is defined -%}
{% for address in item.address.ipv4 -%}
Address={{ address }}
{% endfor -%}
{% endif -%}
{% if item.address.ipv6 is defined -%}
{% for address in item.address.ipv6 -%}
Address={{ address }}
{% endfor -%}
{% endif -%}
{% endif -%} {% endif -%}
{% if item.address.ipv6 is defined %} {% if item.gateway is defined and item.gateway.ipv4 is defined %}
[Address]
Address={{ item.address.ipv6 }}
{% endif -%}
{% if item.gateway.ipv4 is defined %}
[Route] [Route]
Destination=0.0.0.0/0 Destination=0.0.0.0/0
Gateway={{ item.gateway.ipv4 }} Gateway={{ item.gateway.ipv4 }}
@ -36,7 +42,7 @@ Protocol=static
Type=unicast Type=unicast
{% endif -%} {% endif -%}
{% if item.gateway.ipv6 is defined %} {% if item.gateway is defined and item.gateway.ipv6 is defined %}
[Route] [Route]
Destination=::/0 Destination=::/0
Gateway={{ item.gateway.ipv6 }} Gateway={{ item.gateway.ipv6 }}