Defined Type: profile::wmcs::metricsinfra::prometheus_configurator::output_config

Defined in:
modules/profile/manifests/wmcs/metricsinfra/prometheus_configurator/output_config.pp

Overview

SPDX-License-Identifier: Apache-2.0

Parameters:

  • kind (String)
  • options (Hash) (defaults to: {})


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
# File 'modules/profile/manifests/wmcs/metricsinfra/prometheus_configurator/output_config.pp', line 2

define profile::wmcs::metricsinfra::prometheus_configurator::output_config (
    String $kind,
    Hash   $options = {},
) {
    $safe_title = $title.regsubst('[^\w\-]', '_', 'G')

    if $options['units_to_reload'] {
        $units_to_reload_sudo = $options['units_to_reload'].map |String $unit| {
            "ALL = NOPASSWD: /usr/bin/systemctl reload ${unit}"
        }
    } else {
        $units_to_reload_sudo = []
    }

    if $options['units_to_restart'] {
        $units_to_restart_sudo = $options['units_to_restart'].map |String $unit| {
            "ALL = NOPASSWD: /usr/bin/systemctl restart ${unit}"
        }
    } else {
        $units_to_restart_sudo = []
    }

    if $options['blackbox_reload'] {
        $blackbox_reload_sudo = [
            "ALL = NOPASSWD: ${options['blackbox_reload']}"
        ]
    } else {
        $blackbox_reload_sudo = []
    }

    sudo::user { "prometheus-configurator-${safe_title}":
        user       => 'prometheus-configurator',
        privileges => $units_to_reload_sudo + $units_to_restart_sudo + $blackbox_reload_sudo,
    }

    sudo::user { [
        "prometheus-configurator-${safe_title}-reload",
        "prometheus-configurator-${safe_title}-restart",
    ]:
        ensure => absent,
    }

    $config = {
        outputs => [
            $options + {
                kind => $kind,
            }
        ],
    }

    file { "/etc/prometheus-configurator/config.d/output_${safe_title}.yaml":
        ensure  => present,
        owner   => 'prometheus-configurator',
        group   => 'prometheus-configurator',
        content => to_yaml($config),
        mode    => '0440',
    }
}