From 91e5a78ba96645794c8e5742265e17dca83d664f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Hugo=20H=C3=B6rnquist?= Date: Sun, 2 Jan 2022 02:42:48 +0100 Subject: Only run nspawn stuff if machine not running. --- modules/nspawn/manifests/os/arch.pp | 23 ++++++++++++-------- modules/nspawn/manifests/os/debian.pp | 41 +++++++++++++++++++++-------------- 2 files changed, 39 insertions(+), 25 deletions(-) diff --git a/modules/nspawn/manifests/os/arch.pp b/modules/nspawn/manifests/os/arch.pp index 5fbf5d1..0affee1 100644 --- a/modules/nspawn/manifests/os/arch.pp +++ b/modules/nspawn/manifests/os/arch.pp @@ -20,14 +20,19 @@ define nspawn::os::arch ( | 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", + if $facts['machined-info'][$machine]['State'] == 'running' { + notify { "Notify skipping ${machine} setup": + message => "Skipping setup for ${machine}, already running", + } + } else { + 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/modules/nspawn/manifests/os/debian.pp b/modules/nspawn/manifests/os/debian.pp index ac12988..b8a1bd4 100644 --- a/modules/nspawn/manifests/os/debian.pp +++ b/modules/nspawn/manifests/os/debian.pp @@ -37,25 +37,34 @@ define nspawn::os::debian ( | EOF } - file { "/var/lib/machines/${machine}/tmp/puppet7-release-${os_version}.deb": + $puppet_deb = "/var/lib/machines/${machine}/tmp/puppet7-release-${os_version}.deb" + file { $puppet_deb: ensure => file, source => "https://apt.puppet.com/puppet7-release-${os_version}.deb" } - ~> exec { "Set up puppet repo for ${machine}": - command => [ '/usr/bin/systemd-nspawn', - '-M', $machine, - '--quiet', - '/bin/sh', '-c', - "dpkg -i '/tmp/puppet7-release-${os_version}.deb' && apt update" - ], - } - exec { "install puppet-agent on ${machine}": - command => [ '/usr/bin/systemd-nspawn', - '-M', $machine, - '--quiet', - 'apt', 'install', 'puppet-agent', - ], - creates => "/var/lib/machines/${machine}/opt/puppetlabs/bin/puppet", + if $facts['machined-info'][$machine]['State'] == 'running' { + notify { "Notify skipping ${machine} setup": + message => "Skipping setup for ${machine}, already running", + } + } else { + exec { "Set up puppet repo for ${machine}": + subscribe => File[$puppet_deb], + command => [ '/usr/bin/systemd-nspawn', + '-M', $machine, + '--quiet', + '/bin/sh', '-c', + "dpkg -i '/tmp/puppet7-release-${os_version}.deb' && apt update" + ], + } + + exec { "install puppet-agent on ${machine}": + command => [ '/usr/bin/systemd-nspawn', + '-M', $machine, + '--quiet', + 'apt', 'install', 'puppet-agent', + ], + creates => "/var/lib/machines/${machine}/opt/puppetlabs/bin/puppet", + } } } -- cgit v1.2.3