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
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
|
# File 'manifests/server/read_database.pp', line 4
class puppetdb::server::read_database (
$read_database_host = $puppetdb::params::read_database_host,
$read_database_port = $puppetdb::params::read_database_port,
$read_database_username = $puppetdb::params::read_database_username,
$read_database_password = $puppetdb::params::read_database_password,
$read_database_name = $puppetdb::params::read_database_name,
$manage_db_password = $puppetdb::params::manage_read_db_password,
$jdbc_ssl_properties = $puppetdb::params::read_database_jdbc_ssl_properties,
$database_validate = $puppetdb::params::read_database_validate,
$conn_max_age = $puppetdb::params::read_conn_max_age,
$conn_lifetime = $puppetdb::params::read_conn_lifetime,
$confdir = $puppetdb::params::confdir,
$puppetdb_user = $puppetdb::params::puppetdb_user,
$puppetdb_group = $puppetdb::params::puppetdb_group,
$database_max_pool_size = $puppetdb::params::read_database_max_pool_size,
$postgresql_ssl_on = $puppetdb::params::postgresql_ssl_on,
$ssl_cert_path = $puppetdb::params::ssl_cert_path,
$ssl_key_pk8_path = $puppetdb::params::ssl_key_pk8_path,
$ssl_ca_cert_path = $puppetdb::params::ssl_ca_cert_path
) inherits puppetdb::params {
if $read_database_host != undef {
if str2bool($database_validate) {
# Validate the database connection. If we can't connect, we want to fail
# and skip the rest of the configuration, so that we don't leave puppetdb
# in a broken state.
#
# NOTE:
# Because of a limitation in the postgres module this will break with
# a duplicate declaration if read and write database host+name are the
# same.
class { 'puppetdb::server::validate_read_db':
database_host => $read_database_host,
database_port => $read_database_port,
database_username => $read_database_username,
database_password => $read_database_password,
database_name => $read_database_name,
}
}
$read_database_ini = "${confdir}/read_database.ini"
file { $read_database_ini:
ensure => file,
owner => $puppetdb_user,
group => $puppetdb_group,
mode => '0600',
}
$file_require = File[$read_database_ini]
$ini_setting_require = str2bool($database_validate) ? {
false => $file_require,
default => [$file_require, Class['puppetdb::server::validate_read_db']],
}
# Set the defaults
Ini_setting {
path => $read_database_ini,
ensure => present,
section => 'read-database',
require => $ini_setting_require,
}
if !empty($jdbc_ssl_properties) {
$database_suffix = $jdbc_ssl_properties
}
else {
$database_suffix = ''
}
$subname_default = "//${read_database_host}:${read_database_port}/${read_database_name}${database_suffix}"
if $postgresql_ssl_on and !empty($jdbc_ssl_properties) {
fail("Variables 'postgresql_ssl_on' and 'jdbc_ssl_properties' can not be used at the same time!")
}
if $postgresql_ssl_on {
$subname = @("EOT"/L)
${subname_default}?\
ssl=true&sslfactory=org.postgresql.ssl.LibPQFactory&\
sslmode=verify-full&sslrootcert=${ssl_ca_cert_path}&\
sslkey=${ssl_key_pk8_path}&sslcert=${ssl_cert_path}\
| EOT
} else {
$subname = $subname_default
}
ini_setting { 'puppetdb_read_database_username':
setting => 'username',
value => $read_database_username,
}
if $read_database_password != undef and $manage_db_password {
ini_setting { 'puppetdb_read_database_password':
setting => 'password',
value => $read_database_password,
}
}
ini_setting { 'puppetdb_read_pgs':
setting => 'syntax_pgs',
value => true,
}
ini_setting { 'puppetdb_read_subname':
setting => 'subname',
value => $subname,
}
ini_setting { 'puppetdb_read_conn_max_age':
setting => 'conn-max-age',
value => $conn_max_age,
}
ini_setting { 'puppetdb_read_conn_lifetime':
setting => 'conn-lifetime',
value => $conn_lifetime,
}
if $puppetdb::params::database_max_pool_size_setting_name != undef {
if $database_max_pool_size == 'absent' {
ini_setting { 'puppetdb_read_database_max_pool_size':
ensure => absent,
setting => $puppetdb::params::database_max_pool_size_setting_name,
}
} elsif $database_max_pool_size != undef {
ini_setting { 'puppetdb_read_database_max_pool_size':
setting => $puppetdb::params::database_max_pool_size_setting_name,
value => $database_max_pool_size,
}
}
} else {
file { "${confdir}/read_database.ini":
ensure => absent,
}
}
} else {
file { "${confdir}/read_database.ini":
ensure => absent,
}
}
}
|