From dfa81fe29a6be169d6ed2803c4bedcd211b16d72 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Hugo=20H=C3=B6rnquist?= Date: Thu, 13 Jan 2022 23:15:11 +0100 Subject: Nspawn cleanup. --- manifests/util/disable_networking.pp | 14 ++++++++------ manifests/util/enable_networkd.pp | 20 +++++++++++--------- 2 files changed, 19 insertions(+), 15 deletions(-) (limited to 'manifests/util') diff --git a/manifests/util/disable_networking.pp b/manifests/util/disable_networking.pp index ac55951..22d431f 100644 --- a/manifests/util/disable_networking.pp +++ b/manifests/util/disable_networking.pp @@ -1,18 +1,20 @@ define nspawn::util::disable_networking ( - String $machine = $name, - String $machine_path = "/var/lib/machines/${machine}", + String $template_name = $name, + String $template_dir = $nspawn::template_dir, + String $template_path = "${template_dir}/${template_name}.base", ) { - $running = $facts['machined-info'][$machine] != undef and $facts['machined-info'][$machine]['State'] == 'running' + $running = $facts['machined-info'][$template_name] != undef + and $facts['machined-info'][$template_name]['State'] == 'running' $cmd = if $running { - [ 'systemctl', '-M', $machine, 'disable', 'networking' ] + [ 'systemctl', '-M', $template_name, 'disable', 'networking' ] } else { - [ 'systemd-nspawn', '-M', $machine, '--quiet', + [ 'systemd-nspawn', '-M', $template_name, '--quiet', 'systemctl', 'disable', 'networking' ] } - exec { "Disable networking on ${machine}": + exec { "Disable networking on ${template_name}": command => $cmd, path => [ '/bin', '/usr/bin', ], # among others diff --git a/manifests/util/enable_networkd.pp b/manifests/util/enable_networkd.pp index f9b4d2e..40cb3d9 100644 --- a/manifests/util/enable_networkd.pp +++ b/manifests/util/enable_networkd.pp @@ -1,12 +1,13 @@ define nspawn::util::enable_networkd ( - String $machine = $name, - String $machine_path = "/var/lib/machines/${machine}", + String $template_name = $name, + String $template_dir = $nspawn::template_dir, + String $root = "${template_dir}/${template_name}", ) { - networking::networkd_instance { "Initial networking on ${machine}": + networking::networkd_instance { "Initial networking on ${template_name}": priority => 99, filename => 'puppet-initial', - path => "${machine_path}/${networking::networkd::path}", + path => "${root}/${networking::networkd::path}", content => { 'Match' => { 'Name' => 'host0', @@ -18,20 +19,21 @@ define nspawn::util::enable_networkd ( }, } - $running = $facts['machined-info'][$machine] != undef and $facts['machined-info'][$machine]['State'] == 'running' + $running = $facts['machined-info'][$template_name] != undef + and $facts['machined-info'][$template_name]['State'] == 'running' $cmd = if $running { - [ 'systemctl', '-M', $machine, 'enable', 'systemd-networkd' ] + [ 'systemctl', '-M', $template_name, 'enable', 'systemd-networkd' ] } else { - [ 'systemd-nspawn', '-M', $machine, '--quiet', + [ 'systemd-nspawn', '-M', $template_name, '--quiet', 'systemctl', 'enable', 'systemd-networkd' ] } - exec { "Enable systemd-networkd on ${machine}": + exec { "Enable systemd-networkd on ${template_name}": command => $cmd, path => [ '/bin', '/usr/bin', ], # among others - creates => "${machine_path}/etc/systemd/system/multi-user.target.wants/systemd-networkd.service", + creates => "${root}/etc/systemd/system/multi-user.target.wants/systemd-networkd.service", } } -- cgit v1.2.3