summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorHugo Hörnquist <hugo@lysator.liu.se>2022-01-02 02:42:48 +0100
committerHugo Hörnquist <hugo@lysator.liu.se>2022-01-02 02:47:35 +0100
commit14cc76fa1b083f65103beec77232b34459f5efbd (patch)
treeb483a2175edb653116a564e9bee1470eda0a3106
parentAdd systemd-machined facts. (diff)
downloadnspawn-14cc76fa1b083f65103beec77232b34459f5efbd.tar.gz
nspawn-14cc76fa1b083f65103beec77232b34459f5efbd.tar.xz
Only run nspawn stuff if machine not running.
-rw-r--r--manifests/os/arch.pp23
-rw-r--r--manifests/os/debian.pp41
2 files changed, 39 insertions, 25 deletions
diff --git a/manifests/os/arch.pp b/manifests/os/arch.pp
index 5fbf5d1..0affee1 100644
--- a/manifests/os/arch.pp
+++ b/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/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",
+ }
}
}