Puppet Class: puppetmaster::scripts

Defined in:
modules/puppetmaster/manifests/scripts.pp

Overview

Class: puppetmaster::scripts

This class installs some puppetmaster server side scripts required for the manifests

Parameters

keep_reports_minutes

Number of minutes to keep older reports for before deleting them. The job to remove these is run only every 8 hours, however, to prevent excess load on the prod puppetmasters.

Parameters:

  • keep_reports_minutes (Integer) (defaults to: 960)
  • has_puppetdb (Boolean) (defaults to: true)
  • ca_server (Stdlib::Host) (defaults to: $facts['fqdn'])
  • upload_facts (Boolean) (defaults to: true)
  • servers (Hash[String, Puppetmaster::Backends]) (defaults to: {})
  • http_proxy (Optional[Stdlib::HTTPUrl]) (defaults to: undef)


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
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
97
98
# File 'modules/puppetmaster/manifests/scripts.pp', line 12

class puppetmaster::scripts(
    Integer                              $keep_reports_minutes = 960, # 16 hours
    Boolean                              $has_puppetdb         = true,
    Stdlib::Host                         $ca_server            = $facts['fqdn'],
    Boolean                              $upload_facts         = true,
    Hash[String, Puppetmaster::Backends] $servers              = {},
    Optional[Stdlib::HTTPUrl]            $http_proxy             = undef,
){

    $masters = $servers.keys().filter |$server| { $server != $facts['fqdn'] }
    $workers = $servers.values().map |$worker| {
        $worker.map |$name| { $name['worker'] }.filter |$name| { $name != $facts['fqdn'] }
    }.flatten()
    $puppet_merge_conf = @("CONF")
    # Generated by Puppet
    MASTERS="${masters.join(' ')}"
    WORKERS="${workers.join(' ')}"
    CA_SERVER="${ca_server}"
    | CONF

    # export and sanitize facts for puppet compiler
    ensure_packages(['python3-requests', 'python3-yaml'])

    file{'/etc/puppet-merge.conf':
        ensure  => file,
        owner   => 'root',
        group   => 'root',
        mode    => '0555',
        content => $puppet_merge_conf,
    }

    file{'/usr/local/bin/puppet-merge':
        ensure => present,
        owner  => 'root',
        group  => 'root',
        mode   => '0555',
        source => 'puppet:///modules/puppetmaster/puppet-merge.sh',
    }
    file{'/usr/local/bin/puppet-merge.py':
        ensure => present,
        owner  => 'root',
        group  => 'root',
        mode   => '0555',
        source => 'puppet:///modules/puppetmaster/puppet-merge.py',
    }

    $puppet_facts_export_source = $has_puppetdb ? {
        false   => 'puppet:///modules/puppetmaster/puppet-facts-export-nodb.sh',
        default => 'puppet:///modules/puppetmaster/puppet-facts-export-puppetdb.py',
    }
    file { '/usr/local/bin/puppet-facts-export':
        ensure => present,
        owner  => 'root',
        group  => 'root',
        mode   => '0555',
        source => $puppet_facts_export_source,
    }

    file { '/usr/local/sbin/puppet-facts-upload':
        ensure => stdlib::ensure($upload_facts, 'file'),
        owner  => 'root',
        group  => 'root',
        mode   => '0554',
        source => 'puppet:///modules/puppetmaster/puppet-facts-upload.py',
    }

    $timer_command = $http_proxy ? {
        undef   => '/usr/local/sbin/puppet-facts-upload',
        default => "/usr/local/sbin/puppet-facts-upload --proxy ${http_proxy}"
    }
    systemd::timer::job { 'upload_puppet_facts':
        ensure      => $upload_facts.bool2str('present', 'absent'),
        user        => 'root',
        description => 'Upload facts export to puppet compiler',
        command     => $timer_command,
        interval    => {'start' => 'OnUnitInactiveSec', 'interval' => '24h'},
    }

    # Clear out older reports
    systemd::timer::job { 'remove_old_puppet_reports':
        ensure      => 'present',
        user        => 'root',
        description => 'Clears out older puppet reports.',
        command     => "/usr/bin/find /var/lib/puppet/reports -type f -mmin +${keep_reports_minutes} -delete",
        interval    => {'start' => 'OnUnitInactiveSec', 'interval' => '8h'},
    }
}