summaryrefslogtreecommitdiff
path: root/manifests/init.pp
blob: fee1e9a291cd471bf630b4e00f54dfd76e8baf87 (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
# @summary Configures systemd nspawn containers
# @param config
#   Shared configuration for all machines, as per systemd.nspawn(5).
#
#   See nspawn::machine's documentation for how it's merged.
#
# @param machines
#   Set of machines to be configured. Creates `nspawn::machine` resources.
#   See that resource type for acceptable options.
#
# @param template_dir
#   Location of template subvolumes.
#
# @param purge
#   Should old .nspawn files be purged.
class nspawn (
  Nspawn::Systemd::Nspawn $config = {
    'Exec'    => {},
    'Files'   => {},
    'Network' => {},
  },
  Stdlib::Absolutepath $template_dir = '/var/lib/templates',
  Hash[String, Hash[String, Any]] $machines = {},
  Boolean $purge = true,
) {
  # These aren't parameters since they aren't configurable.
  # However, move them to the parameters if it turns out that
  # different distributions place these files in different places.
  # Location of nspawn files.
  $nspawn_dir = '/etc/systemd/nspawn'
  # Location of machine subvolumes.
  $machine_dir = '/var/lib/machines'

  file { $nspawn_dir:
    ensure  => directory,
    purge   => $purge,
    recurse => true,
  }

  file { $template_dir:
    ensure => directory,
  }

  file { $machine_dir:
    ensure => directory,
  }

  create::resources('nspawn::machine', $machines)
}