Puppet Class: profile::puppetdb::database
- Defined in:
- modules/profile/manifests/puppetdb/database.pp
Summary
Sets up a puppetdb postgresql database.Overview
SPDX-License-Identifier: Apache-2.0
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 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 |
# File 'modules/profile/manifests/puppetdb/database.pp', line 16
class profile::puppetdb::database(
Stdlib::Host $master = lookup('profile::puppetdb::master'),
Stdlib::Datasize $shared_buffers = lookup('profile::puppetdb::database::shared_buffers'),
String $replication_password = lookup('puppetdb::password::replication'),
Hash $users = lookup('profile::puppetdb::database::users'),
Integer $replication_lag_crit = lookup('profile::puppetdb::database::replication_lag_crit'),
Integer $replication_lag_warn = lookup('profile::puppetdb::database::replication_lag_warn'),
String $log_line_prefix = lookup('profile::puppetdb::database::log_line_prefix'),
Boolean $use_replication_slots = lookup('profile::puppetdb::database::use_replication_slots'),
Array[Stdlib::Host] $slaves = lookup('profile::puppetdb::slaves'),
Optional[Stdlib::Unixpath] $ssldir = lookup('profile::puppetdb::database::ssldir'),
Optional[Integer[250]] $log_min_duration_statement = lookup('profile::puppetdb::database::log_min_duration_statement'),
Optional[Integer] $log_autovacuum_min_duration = lookup('profile::puppetdb::database::log_autovacuum_min_duration'),
) {
$pgversion = debian::codename() ? {
'bookworm' => 15,
'bullseye' => 13,
'buster' => 11,
}
if $master == $facts['networking']['fqdn'] {
# db_role is only used for the motd in role::puppetdb
$db_role = 'primary'
$on_master = true
} else {
$db_role = 'replica'
$on_master = false
}
sysctl::parameters { 'postgres_shmem':
values => {
# That is derived after tuning postgresql, deriving automatically is
# not the safest idea yet.
'kernel.shmmax' => 8388608000,
},
}
if $on_master {
$replication_slots = $use_replication_slots ? {
true => $slaves.map |$replica| { "puppetdb_${replica.regsubst('\.', '_', 'G')}" },
default => [],
}
class { 'postgresql::master':
includes => ['tuning.conf'],
root_dir => '/srv/postgres',
use_ssl => true,
ssldir => $ssldir,
log_line_prefix => $log_line_prefix,
log_min_duration_statement => $log_min_duration_statement,
log_autovacuum_min_duration => $log_autovacuum_min_duration,
replication_slots => $replication_slots,
}
} else {
$replication_slot_name = $use_replication_slots ? {
true => "puppetdb_${facts['networking']['fqdn'].regsubst('\.', '_', 'G')}",
default => undef,
}
class { 'postgresql::slave':
includes => ['tuning.conf'],
master_server => $master,
root_dir => '/srv/postgres',
replication_pass => $replication_password,
use_ssl => true,
replication_slot_name => $replication_slot_name,
}
class { 'postgresql::slave::monitoring':
pg_master => $master,
pg_user => 'replication',
pg_password => $replication_password,
pg_database => 'puppetdb',
critical => $replication_lag_crit,
warning => $replication_lag_warn,
}
}
file { "/etc/postgresql/${pgversion}/main/tuning.conf":
ensure => 'file',
owner => 'root',
group => 'root',
mode => '0444',
content => template('puppetmaster/puppetdb/tuning.conf.erb'),
before => Service[$postgresql::server::service_name],
}
$users.each |$pg_name, $config| {
postgresql::user { $pg_name:
* => $config + {'master' => $on_master, 'pgversion' => $pgversion},
}
}
postgresql::db { 'puppetdb':
owner => 'puppetdb',
}
# Ensure dbs created before grants
Postgresql::Db<| |> -> Postgresql::Db_grant<| |>
exec { 'create_tgrm_extension':
command => '/usr/bin/psql puppetdb -c "create extension pg_trgm"',
unless => '/usr/bin/psql puppetdb -c \'\dx\' | /bin/grep -q pg_trgm',
user => 'postgres',
require => Postgresql::Db['puppetdb'],
}
# Allow connections from all the slaves
firewall::service { 'postgresql_puppetdb':
proto => 'tcp',
port => 5432,
srange => $slaves,
}
}
|