From 337716a7f106d35cca86ad0ac69a080356dbc32f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Hugo=20H=C3=B6rnquist?= Date: Sat, 1 Jan 2022 23:07:49 +0100 Subject: Hopefully fix nspawn. --- manifests/machine.pp | 15 ++------------- manifests/os/arch.pp | 43 +++++++++---------------------------------- manifests/os/debian.pp | 6 +++--- manifests/setup.pp | 2 ++ 4 files changed, 16 insertions(+), 50 deletions(-) diff --git a/manifests/machine.pp b/manifests/machine.pp index b308b74..d747069 100644 --- a/manifests/machine.pp +++ b/manifests/machine.pp @@ -1,6 +1,6 @@ define nspawn::machine ( String $os, - String $os_version, + Hash $os_opts = {} , String $machine = $name, Boolean $enable = false, ) { @@ -20,18 +20,7 @@ define nspawn::machine ( | EOF } - case $os { - 'debian': { - nspawn::os::debian { $machine: - os_version => $os_version, - } - } - 'arch': { - nspawn::os::arch { $machine: - } - } - # TODO default fail - } + create_resources("nspawn::os::${os}", { $machine => $os_opts }) service { "systemd-nspawn@${machine}.service": enable => true, diff --git a/manifests/os/arch.pp b/manifests/os/arch.pp index 4f83546..5fbf5d1 100644 --- a/manifests/os/arch.pp +++ b/manifests/os/arch.pp @@ -8,7 +8,7 @@ define nspawn::os::arch ( creates => "/var/lib/machines/${machine}/etc/os-release", } - file { "/var/lib/machines/${machine}/etc/systemd/network.d/20-puppet.conf": + file { "/var/lib/machines/${machine}/etc/systemd/network/20-puppet.conf": content => @(EOF) [Match] Name=host0 @@ -20,39 +20,14 @@ define nspawn::os::arch ( | EOF } - $symlinks = [ - [ '/etc/systemd/system/dbus-org.freedesktop.network1.service', - '/usr/lib/systemd/system/systemd-networkd.service' ], - [ '/etc/systemd/system/multi-user.target.wants/systemd-networkd.service', - '/usr/lib/systemd/system/systemd-networkd.service' ], - [ '/etc/systemd/system/sockets.target.wants/systemd-networkd.socket', - '/usr/lib/systemd/system/systemd-networkd.socket' ], - [ '/etc/systemd/system/sysinit.target.wants/systemd-network-generator.service', - '/usr/lib/systemd/system/systemd-network-generator.service' ], - [ '/etc/systemd/system/network-online.target.wants/systemd-networkd-wait-online.service', - '/usr/lib/systemd/system/systemd-networkd-wait-online.service' ], - ] - - $symlinks.each |$pair| { - $where = $pair[0] - $target = $pair[1] - file { "/var/lib/machines/${machine}/${where}": - ensure => link, - target => $target, - } - } - - - file { "/var/lib/machines/${machine}/etc/systemd/network.d/20-puppet.conf": - content => @(EOF) - [Match] - Name=host0 - - [Network] - Address=10.0.0.43/23 - Gateway=10.0.0.1 - IPv6AcceptRA=1 - | EOF + exec { "Enable systemd-networkd on ${machine}": + command => [ '/usr/bin/systemd-nspawn', + '-M', $machine, + '--quiet', + 'systemctl', 'enable', 'systemd-networkd', + ], + # among others + creates => "/var/lib/machines/${machine}/etc/systemd/system/multi-user.target.wants/systemd-networkd.service", } } diff --git a/manifests/os/debian.pp b/manifests/os/debian.pp index c821ba6..13d9ac9 100644 --- a/manifests/os/debian.pp +++ b/manifests/os/debian.pp @@ -29,11 +29,11 @@ define nspawn::os::debian ( # allow-hotplug host0 iface host0 inet static - address 10.0.0.42/23 - gateway 10.0.0.1 + address 10.0.0.42/23 + gateway 10.0.0.1 iface host0 inet6 auto - private 0 + private 0 | EOF } diff --git a/manifests/setup.pp b/manifests/setup.pp index ffd90ee..9f742fd 100644 --- a/manifests/setup.pp +++ b/manifests/setup.pp @@ -1,5 +1,7 @@ class nspawn::setup { + # TODO find better file to use for containers + file { '/usr/lib/systemd/resolv.conf': ensure => file, content => @(EOF) -- cgit v1.2.3