Puppet Class: puppetdb::app

Defined in:
modules/puppetdb/manifests/app.pp

Overview

SPDX-License-Identifier: Apache-2.0

Class puppetdb::app

Sets up the puppetdb clojure app. This assumes you're using …magic!

Parameters

Parameters:

  • gc_interval (Integer[0]) (defaults to: 20)

    This controls how often, in minutes, to compact the database. The compaction process reclaims space and deletes unnecessary rows. If not supplied, the default is every 60 minutes. If set to zero, all database GC processes will be disabled.

  • node_ttl (Pattern[/\d+[dhms]/]) (defaults to: '7d')

    Mark as ‘expired’ nodes that haven’t seen any activity (no new catalogs, facts, or reports) in the specified amount of time. Expired nodes behave the same as manually-deactivated nodes.

  • node_purge_ttl (Pattern[/\d+[dhms]/]) (defaults to: '14d')

    Automatically delete nodes that have been deactivated or expired for the specified amount of time

  • report_ttl (Pattern[/\d+[dhms]/]) (defaults to: '1d')

    Automatically delete reports that are older than the specified amount of time.

  • jvm_opts (String) (defaults to: '-Xmx4G')
  • db_user (String) (defaults to: 'puppetdb')
  • db_driver (Enum['hsqldb', 'postgres']) (defaults to: 'postgres')
  • ssldir (Stdlib::Unixpath) (defaults to: puppet_ssldir())
  • ca_path (Stdlib::Unixpath) (defaults to: '/etc/ssl/certs/Puppet_Internal_CA.pem')
  • tmpfs_stockpile_queue (Boolean) (defaults to: false)
  • command_processing_threads (Integer) (defaults to: 16)
  • log_level (Puppetdb::Loglevel) (defaults to: 'info')
  • facts_blacklist (Array[String]) (defaults to: [])
  • facts_blacklist_type (Enum['literal', 'regex']) (defaults to: 'literal')
  • db_rw_host (Stdlib::Host) (defaults to: $facts['fqdn'])
  • bind_ip (Optional[Stdlib::IP::Address]) (defaults to: undef)
  • bind_ip_insecure (Optional[Stdlib::IP::Address]) (defaults to: undef)
  • db_ro_host (Optional[String]) (defaults to: undef)
  • db_password (Optional[String]) (defaults to: undef)
  • db_ro_password (Optional[String]) (defaults to: undef)


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
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
# File 'modules/puppetdb/manifests/app.pp', line 20

class puppetdb::app(
    String                        $jvm_opts                   = '-Xmx4G',
    String                        $db_user                    = 'puppetdb',
    Enum['hsqldb', 'postgres']    $db_driver                  = 'postgres',
    Stdlib::Unixpath              $ssldir                     = puppet_ssldir(),
    Stdlib::Unixpath              $ca_path                    = '/etc/ssl/certs/Puppet_Internal_CA.pem',
    Boolean                       $tmpfs_stockpile_queue      = false,
    Integer                       $command_processing_threads = 16,
    Puppetdb::Loglevel            $log_level                  = 'info',
    Array[String]                 $facts_blacklist            = [],
    Enum['literal', 'regex']      $facts_blacklist_type       = 'literal',
    Integer[0]                    $gc_interval                = 20,
    Pattern[/\d+[dhms]/]          $node_ttl                   = '7d',
    Pattern[/\d+[dhms]/]          $node_purge_ttl             = '14d',
    Pattern[/\d+[dhms]/]          $report_ttl                 = '1d',
    Stdlib::Host                  $db_rw_host                 = $facts['fqdn'],
    Optional[Stdlib::IP::Address] $bind_ip                    = undef,
    Optional[Stdlib::IP::Address] $bind_ip_insecure           = undef,
    Optional[String]              $db_ro_host                 = undef,
    Optional[String]              $db_password                = undef,
    Optional[String]              $db_ro_password             = undef,
) {
    # PuppetDB installation

    ensure_packages('puppetdb')
    $vardir              = '/var/lib/puppetdb'
    $stockpile_queue_dir = "${vardir}/stockpile/cmd/q"

    file { $vardir:
        ensure => directory,
        owner  => 'puppetdb',
        group  => 'puppetdb',
        mode   => '0755',
    }
    $stockpile_mount_ensure = $tmpfs_stockpile_queue ? {
        true    => 'mounted',
        default => 'absent',
    }

    if $facts.has_key('puppetdb') and $facts['puppetdb']['stockpile_initialized'] {
        mount { $stockpile_queue_dir:
            ensure  => $stockpile_mount_ensure,
            atboot  => true,
            device  => 'tmpfs',
            fstype  => 'tmpfs',
            options => 'uid=puppetdb,gid=puppetdb',
            notify  => Service['puppetdb'],
        }
    }

    file { '/etc/default/puppetdb':
        ensure  => present,
        owner   => 'root',
        group   => 'root',
        content => template('puppetdb/etc/default/puppetdb.erb'),
    }

    service { 'puppetdb':,
        ensure => running,
        enable => true,
    }

    ## Configuration
    file { '/etc/puppetdb':
        ensure  => directory,
        require => Package['puppetdb'],
    }
    file { '/etc/puppetdb/conf.d':
        ensure  => directory,
        owner   => 'puppetdb',
        group   => 'root',
        mode    => '0750',
        recurse => true,
        purge   => true,
    }

    $postgres_uri = "ssl=true&sslfactory=org.postgresql.ssl.jdbc4.LibPQFactory&sslmode=verify-full&sslrootcert=${ca_path}"
    $postgres_rw_db_subname = "//${db_rw_host}:5432/puppetdb?${postgres_uri}"
    $postgres_ro_db_subname = "//${db_ro_host}:5432/puppetdb?${postgres_uri}"

    $db_settings = {
        'report-ttl'           => $report_ttl,
        'gc-interval'          => $gc_interval,
        'node-ttl'             => $node_ttl,
        'node-purge-ttl'       => $node_purge_ttl,
        'subname'              => $postgres_rw_db_subname,
        'username'             => 'puppetdb',
        'password'             => $db_password,
        'facts-blacklist-type' => $facts_blacklist_type,
        'facts-blacklist'      => $facts_blacklist.join(', '),
    }
    $read_db_settings = {
        'subname'  => $postgres_ro_db_subname,
        'username' => 'puppetdb_ro',
        'password' => $db_ro_password,
    }

    puppetdb::config { 'database':
        settings => $db_settings,
    }
    if $db_ro_host and $db_driver == 'postgres' {
        puppetdb::config { 'read-database':
            settings => $read_db_settings,
        }
    }

    puppetdb::config { 'global':
        settings => {
            'vardir'         => $vardir,
            'logging-config' => '/etc/puppetdb/logback.xml',
        },
    }

    puppetdb::config { 'nrepl':
        settings => {'enabled' => false},
    }

    # TODO: consider using profile::pki::get_cert
    puppet::expose_agent_certs { '/etc/puppetdb':
        ensure          => present,
        provide_private => true,
        user            => 'puppetdb',
        group           => 'puppetdb',
        ssldir          => $ssldir,
    }

    $_bind_ip = $bind_ip ? {
        undef   => {},
        default => {'ssl-host' => $bind_ip}
    }
    $_bind_ip_insecure = $bind_ip_insecure ? {
        undef   => {},
        default => {'host' => $bind_ip_insecure}
    }
    $jetty_settings = {
        'port'        => 8080,
        'ssl-port'    => 8081,
        'ssl-key'     => '/etc/puppetdb/ssl/server.key',
        'ssl-cert'    => '/etc/puppetdb/ssl/cert.pem',
        'ssl-ca-cert' => $ca_path,
    } + $_bind_ip + $_bind_ip_insecure

    puppetdb::config { 'jetty':
        settings => $jetty_settings,
        require  => Puppet::Expose_agent_certs['/etc/puppetdb'],
    }

    puppetdb::config { 'command-processing':
        settings => {
            'threads' => $command_processing_threads,
        },
    }
    file {'/etc/puppetdb/logback.xml':
        ensure  => file,
        owner   => 'root',
        group   => 'root',
        mode    => '0644',
        content => template('puppetdb/logback.xml.erb'),
    }
}