summaryrefslogtreecommitdiff
path: root/modules/nspawn/manifests/os/debian.pp
blob: b8a1bd404cc09aa0709eb1fd1c3802c7928120a7 (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
63
64
65
66
67
68
69
70
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",
  }

  file { "/var/lib/machines/${machine}/etc/network/interfaces":
    ensure  => file,
    content => @(EOF)
    # File managed by puppet
    # See interfaces(5)
    source-directory /etc/network/interfaces.d
    | EOF
  }

  file { "/var/lib/machines/${machine}/etc/network/interfaces.d":
    ensure  => directory,
  }

  file { "/var/lib/machines/${machine}/etc/network/interfaces.d/puppet":
    ensure  => file,
    content => @(EOF)
    # File managed by puppet
    auto host0
    # allow-hotplug host0

    iface host0 inet static
      address 10.0.0.42/23
      gateway 10.0.0.1

    iface host0 inet6 auto
      private 0
    | EOF
  }

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

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