aboutsummaryrefslogtreecommitdiff
path: root/manifests/conf.pp
blob: f8f5baa5195cebceb42a9cd7b5bcf898718751a1 (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
# @summary Sets up a environment file.
#
# Configures an environment file along with a systemd dropin unit for
# loading that file.
#
# @param env
#   Environment to set.
# @param service
#   Which service this environment belongs to.
#   Also configures which service file a dropin will be created for,
#   along with which service should be notified that its environment
#   was updated.
# @param absolutepath
#   Absolute path to the configuration file.
#   If this is left unset, then it defaults to
#   `${concourse::confdir::conf_dir}/${relative_path}`.
#
#   It's recommended to keep it that way.
# @param relative_path
#   Basename of the generated environment file.
# @param ensure
# @api private
define concourse::conf (
  Hash[String, Any] $env,
  String $service,
  Optional[Stdlib::Absolutepath] $absolutepath = undef,
  String $relative_path = $name,
  Enum['absent', 'present'] $ensure = 'present',
) {
  include concourse::confdir

  if $absolutepath {
    $path = $absolutepath
  } else {
    $path = "${concourse::confdir::conf_dir}/${relative_path}"
  }

  file { $path:
    ensure    => $ensure,
    content   => epp("${module_name}/env.epp", { 'entries' => $env }),
    show_diff => false,
    mode      => '0600',
    notify    => Service[$service],
  }

  $dropin_content = @("EOF")
    [Service]
    EnvironmentFile=${path}
    | EOF

  systemd::dropin_file { "concourse-${name}.conf":
    ensure         => $ensure,
    unit           => "${service}.service",
    content        => $dropin_content,
    notify_service => true,
  }
}