summaryrefslogtreecommitdiff
path: root/manifests/machine.pp
diff options
context:
space:
mode:
authorHugo Hörnquist <hugo@lysator.liu.se>2022-01-13 12:59:43 +0100
committerHugo Hörnquist <hugo@lysator.liu.se>2022-01-13 14:23:37 +0100
commitfe040d1aa9a01e14c882ead7cb09303aef588804 (patch)
tree318e6cdff8aa9138866fc1f0140e37347fe7bf66 /manifests/machine.pp
parentSafeguard machined fact. (diff)
downloadnspawn-fe040d1aa9a01e14c882ead7cb09303aef588804.tar.gz
nspawn-fe040d1aa9a01e14c882ead7cb09303aef588804.tar.xz
Rewrote mots of nspawn.
Diffstat (limited to 'manifests/machine.pp')
-rw-r--r--manifests/machine.pp64
1 files changed, 44 insertions, 20 deletions
diff --git a/manifests/machine.pp b/manifests/machine.pp
index 8ba9bf3..8cc1947 100644
--- a/manifests/machine.pp
+++ b/manifests/machine.pp
@@ -7,32 +7,56 @@ define nspawn::machine (
require ::nspawn::setup
- file { "/var/lib/machines/${machine}/puppet":
- ensure => directory,
+ $domain = $facts['domain']
+
+ # Sets up image
+ # create_resources("nspawn::os::${os}", { $machine => $os_opts })
+ nspawn::os::debian { 'debian-bullseye.base':
+ * => $os_opts,
}
- file { "/etc/systemd/nspawn/${machine}.nspawn":
- content => @("EOF")
- [Exec]
- Hostname=${machine}.adrift.space
- Boot=true
- # /usr/lib/systemd/resolv.conf
- ResolvConf=copy-static
-
- [Files]
- # TODO This should only be mounted on puppet servers, in case it
- # contains secrets
- BindReadOnly=/usr/local/puppet:/puppet
-
- [Network]
- Bridge=br0
- | EOF
+ # Copies image to us
+ exec { "Create ${machine} from template":
+ command => [ 'systemd-nspawn',
+ '--template=/var/lib/machines/debian-bullseye.base',
+ '-D', $machine,
+ ],
+ path => ['/bin','/usr/bin'],
+ cwd => '/var/lib/machines',
+ creates => "/var/lib/machines/${machine}",
+ require => Nspawn::Os::Debian['debian-bullseye.base'],
+ }
+
+ file { "/var/lib/machines/${machine}/etc/hostname":
+ ensure => file,
+ content => "${machine}.${domain}\n",
+ require => Exec["Create ${machine} from template"],
}
- create_resources("nspawn::os::${os}", { $machine => $os_opts })
+ # systemd-nspawn --quiet -M debby systemctl enable puppet
+
+ $nspawn_data = {
+ 'Exec' => {
+ # 'Hostname' => "${machine}.${domain}",
+ 'Boot' => 'true',
+ 'ResolvConf' => 'copy-static', # /usr/lib/systemd/resolv.conf
+ },
+ 'Network' => {
+ 'Bridge' => 'br0',
+ }
+ }
+
+ file { "/etc/systemd/nspawn/${machine}.nspawn":
+ ensure => file,
+ content => epp('nspawn/unit_file.epp', {
+ data => $nspawn_data,
+ }),
+ notify => Service["systemd-nspawn@${machine}.service"],
+ }
service { "systemd-nspawn@${machine}.service":
- enable => $enable,
+ enable => $enable,
+ require => File["/etc/systemd/nspawn/${machine}.nspawn"],
}
}