summaryrefslogtreecommitdiff
path: root/modules/nspawn/manifests/os/debian.pp
blob: fbab9acd1c588e2ee4e207222f4bbd435c717814 (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
define nspawn::os::debian (
  String $os_version,
  String $machine = $name,
) {

  ensure_packages(['debootstrap'])

  exec { "/usr/bin/deboostrap ${os_version} /var/lib/machines/${machine}":
    creates => "/var/lib/machines/${machine}/etc/os-release",
  }

  $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"
  }

  $running = $facts['machined-info'][$machine] != Undef or $facts['machined-info'][$machine]['State'] == 'running' 

  if $running {
    # TODO
    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",
    }
  }

  nspawn::util::disable_networking { $machine: }
  nspawn::util::enable_networkd { $machine: }

}