summaryrefslogtreecommitdiff
path: root/manifests/init.pp
blob: 7b50c023bb60a7bda709d6c8e54959852edaa4f7 (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
define systemd_mount (
  String $what,  # elrond:/files
  String $where = $name, # /usr/net
  Boolean $automount = false,
  String $wantedBy = 'default.target',
  Array[String] $options = [],
) {

  $mostly_fixed = $where.map |$c| {
    $c ? {
      '/'     => '-',
      '-'     => '\\x2d',
      default => $c,
    }
  }.join('')
  $fixed = if $mostly_fixed[0] == '-' {
    $mostly_fixed[1, -1] # drop first char
  } else {
    $mostly_fixed
  }

  systemd::unit_file { "${fixed}.mount":
      content => epp('systemd_mount/mount.epp', {
        what     => $what,
        where    => $where,
        options  => $options,
        wantedby => if ($automount) { '' } else { "WantedBy=${wantedBy}" },
      }),
  }

  if ($automount) {
    systemd::unit_file { "${fixed}.automount":
      content    => epp('systemd_mount/automount.epp', {
        where    => $where,
        wantedBy => "WantedBy=${wantedBy}",
        }),
    }

    service { "${fixed}.automount":
      enable => true,
      ensure => running,
    }
  } else {
    service { "${fixed}.mount":
      enable => true,
      ensure => running,
    }
  }

}