summaryrefslogtreecommitdiff
path: root/manifests/os/debian.pp
blob: 9e42737a9caf6fc8aa9177408d7f999e58010937 (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
# TODO rename this to image-setup
define nspawn::os::debian (
  String $os_version,
  String $template_name = $name,
  String $template_dir = $nspawn::template_dir,
) {

  $root = "${template_dir}/${template_name}"
  $pkg_pos = 'var/tmp'

  ensure_packages(['debootstrap'])

  exec { "/usr/bin/deboostrap ${os_version} '${root}'":
    creates => "${root}/etc/os-release",
  }

  $puppet_deb = "puppet7-release-${os_version}.deb"
  $puppet_deb_path = "${root}/${pkg_pos}/${puppet_deb}"

  file { $puppet_deb_path:
    ensure => file,
    source => "https://apt.puppet.com/${puppet_deb}"
  }

  $running = $facts['machined-info'][$template_name] != undef
         and $facts['machined-info'][$template_name]['State'] == 'running' 

  if $running {
    # TODO
    notify { "Notify skipping ${template_name} setup":
      message => "Skipping setup for ${template_name}, already running",
    }
  } else {
    exec { "Set up puppet repo for ${template_name}":
      subscribe   => File[$puppet_deb_path],
      refreshonly => true,
      command     => [ '/usr/bin/systemd-nspawn',
      '-M', $template_name,
      '--quiet',
      '/bin/sh', '-c',
      "dpkg -i '/${pkg_pos}/puppet7-release-${os_version}.deb' && apt update"
      ],
    }

    exec { "install puppet-agent on ${template_name}":
      command => [ '/usr/bin/systemd-nspawn',
      '-M', $template_name,
      '--quiet',
      'apt', 'install', 'puppet-agent',
      ],
      creates => "${root}/opt/puppetlabs/bin/puppet",
    }
  }

  nspawn::util::disable_networking { $template_name: 
    template_dir => $template_dir,
  }
  nspawn::util::enable_networkd { $template_name: 
    template_dir => $template_dir,
  }
}