Defined Type: systemd::dropin_file

Defined in:
manifests/dropin_file.pp

Overview

Creates a drop-in file for a systemd unit

Parameters:

  • unit (Systemd::Unit)

    The target unit file to create

  • filename (Systemd::Dropin) (defaults to: $name)

    The filename of the drop in. The full path is determined using the path, unit and this filename.

  • ensure (Enum['present', 'absent', 'file']) (defaults to: 'present')

    the state of this dropin file

  • path (Stdlib::Absolutepath) (defaults to: '/etc/systemd/system')

    The main systemd configuration path

  • selinux_ignore_defaults (Boolean) (defaults to: false)

    If Puppet should ignore the default SELinux labels.

  • content (Optional[Variant[String,Sensitive[String]]]) (defaults to: undef)

    The full content of the unit file (Mutually exclusive with ‘$source`)

  • source (Optional[String]) (defaults to: undef)

    The ‘File` resource compatible `source` Mutually exclusive with “$content“

  • target (Optional[Stdlib::Absolutepath]) (defaults to: undef)

    If set, will force the file to be a symlink to the given target (Mutually exclusive with both ‘$source` and `$content`

  • owner (String) (defaults to: 'root')

    The owner to set on the dropin file

  • group (String) (defaults to: 'root')

    The group to set on the dropin file

  • mode (String) (defaults to: '0444')

    The mode to set on the dropin file

  • show_diff (Boolean) (defaults to: true)

    Whether to show the diff when updating dropin file

  • notify_service (Boolean) (defaults to: true)

    Notify a service for the unit, if it exists

  • daemon_reload (Boolean) (defaults to: true)

    Call systemd::daemon_reload

See Also:

  • systemdsystemd.unit(5)


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
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
# File 'manifests/dropin_file.pp', line 22

define systemd::dropin_file (
  Systemd::Unit                               $unit,
  Systemd::Dropin                             $filename                = $name,
  Enum['present', 'absent', 'file']           $ensure                  = 'present',
  Stdlib::Absolutepath                        $path                    = '/etc/systemd/system',
  Boolean                                     $selinux_ignore_defaults = false,
  Optional[Variant[String,Sensitive[String]]] $content                 = undef,
  Optional[String]                            $source                  = undef,
  Optional[Stdlib::Absolutepath]              $target                  = undef,
  String                                      $owner                   = 'root',
  String                                      $group                   = 'root',
  String                                      $mode                    = '0444',
  Boolean                                     $show_diff               = true,
  Boolean                                     $notify_service          = true,
  Boolean                                     $daemon_reload           = true,
) {
  include systemd

  if $target {
    $_ensure = 'link'
  } else {
    $_ensure = $ensure ? {
      'present' => 'file',
      default   => $ensure,
    }
  }

  $full_filename = "${path}/${unit}.d/${filename}"

  if $ensure != 'absent' {
    ensure_resource('file', dirname($full_filename), {
        ensure                  => directory,
        owner                   => 'root',
        group                   => 'root',
        recurse                 => $systemd::purge_dropin_dirs,
        purge                   => $systemd::purge_dropin_dirs,
        selinux_ignore_defaults => $selinux_ignore_defaults,
    })
  }

  file { $full_filename:
    ensure                  => $_ensure,
    content                 => $content,
    source                  => $source,
    target                  => $target,
    owner                   => $owner,
    group                   => $group,
    mode                    => $mode,
    selinux_ignore_defaults => $selinux_ignore_defaults,
    show_diff               => $show_diff,
  }

  if $daemon_reload {
    ensure_resource('systemd::daemon_reload', $unit)

    File[$full_filename] ~> Systemd::Daemon_reload[$unit]
  }

  if $notify_service {
    File[$full_filename] ~> Service <| title == $unit or name == $unit |>

    if $daemon_reload {
      Systemd::Daemon_reload[$unit] ~> Service <| title == $unit or name == $unit |>
    }

    if $unit =~ /\.service$/ {
      $short_service_name = regsubst($unit, /\.service$/, '')
      File[$full_filename] ~> Service <| title == $short_service_name or name == $short_service_name |>

      if $daemon_reload {
        Systemd::Daemon_reload[$unit] ~> Service <| title == $short_service_name or name == $short_service_name |>
      }
    }
  }
}