Skip to content

Commit

Permalink
support vlans
Browse files Browse the repository at this point in the history
  • Loading branch information
akerl committed Oct 10, 2023
1 parent 196b08f commit 4209877
Show file tree
Hide file tree
Showing 4 changed files with 35 additions and 1 deletion.
2 changes: 2 additions & 0 deletions manifests/init.pp
Expand Up @@ -4,12 +4,14 @@
# @param domains list of domains for search path
# @param dnsovertls enable DNS over TLS
# @param bridges sets interfaces which should be bridged
# @param vlans sets which virtual interfaces should be created
# @param ignore sets interface regex patterns to not create network configurations for
class network (
Array[String] $resolvers = ['8.8.8.8#dns.google', '8.8.4.4#dns.google'],
Array[String] $domains = [],
Boolean $dnsovertls = true,
Hash[String, Array[String]] $bridges = {},
Hash[String, Hash[String, String]] $vlans = {},
Array[String] $ignore = ['^lo$', '^docker\d+$', '^(tap|veth)', '^wg\d+'],
) {
case $facts['os']['family'] {
Expand Down
17 changes: 16 additions & 1 deletion manifests/systemd.pp
Expand Up @@ -5,6 +5,7 @@
$domains = $network::domains
$dnsovertls = $network::dnsovertls
$bridges = $network::bridges
$vlans = $network::vlans
$ignore = $network::ignore

file { '/etc/resolv.conf':
Expand Down Expand Up @@ -46,8 +47,22 @@

$bridge_children = values($bridges).flatten

$vlans.each |String $vlan_name, Hash[String, String] $params| {
file { "/etc/systemd/network/${vlan_name}.network":
ensure => file,
content => template('network/vlan.network.erb'),
notify => Service['systemd-networkd'],
}

file { "/etc/systemd/network/${vlan_name}.netdev":
ensure => file,
content => template('network/vlan.netdev.erb'),
notify => Service['systemd-networkd'],
}
}

$facts['networking']['interfaces'].each |String $iface, Any $value| {
unless $iface in $bridge_children or $iface in $bridges or $ignore.any |$item| { $iface.match($item) } {
unless $iface in $bridge_children or $iface in $bridges or $iface in $vlans or $ignore.any |$item| { $iface.match($item) } {
file { "/etc/systemd/network/${iface}.network":
ensure => file,
content => template('network/interface.network.erb'),
Expand Down
7 changes: 7 additions & 0 deletions templates/vlan.netdev.erb
@@ -0,0 +1,7 @@
[NetDev]
Name=<%= @vlan_name %>
Kind=vlan
MACAddress=<%= @params['mac'] %>

[VLAN]
Id=<%= @params['id'] %>
10 changes: 10 additions & 0 deletions templates/vlan.network.erb
@@ -0,0 +1,10 @@
[Match]
Name=<%= @vlan_name %>
Type=vlan

[Network]
DHCP=yes
LLMNR=no

[DHCPv4]
UseDNS=no

0 comments on commit 4209877

Please sign in to comment.