summaryrefslogtreecommitdiff
path: root/manifests/machine.pp
blob: 8cc19471458315e73247b3839a2fe244f3c15f18 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
define nspawn::machine (
  String $os,
  Hash $os_opts = {} ,
  String $machine = $name,
  Boolean $enable = false,
) {

  require ::nspawn::setup

  $domain = $facts['domain']

  # Sets up image
  # create_resources("nspawn::os::${os}", { $machine => $os_opts })
  nspawn::os::debian { 'debian-bullseye.base':
    * => $os_opts,
  }

  # 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"],
  }

  # 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,
    require => File["/etc/systemd/nspawn/${machine}.nspawn"],
  }

}