From a261aa089f879b6854c7b8fc7676d6b23ac25588 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Hugo=20H=C3=B6rnquist?= Date: Sun, 2 Jan 2022 04:31:50 +0100 Subject: Network rewrites. --- modules/nspawn/manifests/util/enable_networkd.pp | 35 ++++++++++++++++++++++++ 1 file changed, 35 insertions(+) create mode 100644 modules/nspawn/manifests/util/enable_networkd.pp (limited to 'modules/nspawn/manifests/util/enable_networkd.pp') diff --git a/modules/nspawn/manifests/util/enable_networkd.pp b/modules/nspawn/manifests/util/enable_networkd.pp new file mode 100644 index 0000000..2b532b9 --- /dev/null +++ b/modules/nspawn/manifests/util/enable_networkd.pp @@ -0,0 +1,35 @@ +define nspawn::util::enable_networkd ( + String $machine = $name, + String $machine_path = "/var/lib/machines/${machine}", +) { + + # TODO only do this if the directory is empty + networking::networkd { "Initial networking on ${machine}": + filename => '20-puppet-initial', + match => { 'Name' => 'host0', }, + root => $machine_path, + network => { + 'DHCP' => 'ipv4', + 'IPv6AcceptRA' => 1, + }, + notify_ => false, + manage_directory => false, + } + + $running = $facts['machined-info'][$machine] != Undef or $facts['machined-info'][$machine]['State'] == 'running' + + $cmd = if $running { + [ 'systemctl', '-M', $machine, 'enable', 'systemd-networkd' ] + } else { + [ 'systemd-nspawn', '-M', $machine, '--quiet', + 'systemctl', 'enable', 'systemd-networkd' ] + } + + exec { "Enable systemd-networkd on ${machine}": + command => $cmd, + path => [ '/bin', '/usr/bin', ], + # among others + creates => "${machine_path}/etc/systemd/system/multi-user.target.wants/systemd-networkd.service", + } + +} -- cgit v1.2.3