From 14cc76fa1b083f65103beec77232b34459f5efbd 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. --- manifests/os/debian.pp | 41 +++++++++++++++++++++++++---------------- 1 file changed, 25 insertions(+), 16 deletions(-) (limited to 'manifests/os/debian.pp') diff --git a/manifests/os/debian.pp b/manifests/os/debian.pp index ac12988..b8a1bd4 100644 --- a/manifests/os/debian.pp +++ b/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