Puppet Class: postgresql::params

Overview



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
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
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
# File 'manifests/params.pp', line 2

class postgresql::params inherits postgresql::globals {
  $version                      = $postgresql::globals::globals_version
  $postgis_version              = $postgresql::globals::globals_postgis_version
  $listen_addresses             = undef
  $port                         = 5432
  $log_line_prefix              = undef
  $ip_mask_deny_postgres_user   = '0.0.0.0/0'
  $ip_mask_allow_all_users      = '127.0.0.1/32'
  $ipv4acls                     = []
  $ipv6acls                     = []
  $encoding                     = $postgresql::globals::encoding
  $locale                       = $postgresql::globals::locale
  $data_checksums               = $postgresql::globals::data_checksums
  $timezone                     = $postgresql::globals::timezone
  $service_ensure               = 'running'
  $service_enable               = true
  $service_manage               = true
  $service_restart_on_change    = true
  $service_provider             = $postgresql::globals::service_provider
  $manage_pg_hba_conf           = pick($manage_pg_hba_conf, true)
  $manage_pg_ident_conf         = pick($manage_pg_ident_conf, true)
  $manage_recovery_conf         = pick($manage_recovery_conf, false)
  $manage_postgresql_conf_perms = pick($manage_postgresql_conf_perms, true)
  $manage_selinux               = pick($manage_selinux, false)
  $package_ensure               = 'present'
  $module_workdir               = pick($module_workdir,'/tmp')
  $password_encryption          = pick($password_encryption, versioncmp($version, '14') ? { -1 => 'md5', default => 'scram-sha-256' })
  $extra_systemd_config         = undef
  $manage_datadir               = true
  $manage_logdir                = true
  $manage_xlogdir               = true

  $backup_enable = false
  $backup_provider = 'pg_dump'

  # Amazon Linux's OS Family is 'Linux', operating system 'Amazon'.
  case $facts['os']['family'] {
    'RedHat', 'Linux': {
      $link_pg_config     = true
      $user               = pick($user, 'postgres')
      $group              = pick($group, 'postgres')
      $needs_initdb       = pick($needs_initdb, true)
      $version_parts      = split($version, '[.]')
      $package_version    = "${version_parts[0]}${version_parts[1]}"

      if $version == $postgresql::globals::default_version and $facts['os']['name'] != 'Amazon' or $postgresql::globals::manage_dnf_module {
        $client_package_name    = pick($client_package_name, 'postgresql')
        $server_package_name    = pick($server_package_name, 'postgresql-server')
        $contrib_package_name   = pick($contrib_package_name,'postgresql-contrib')
        $devel_package_name     = pick($devel_package_name, 'postgresql-devel')
        $java_package_name      = pick($java_package_name, 'postgresql-jdbc')
        $docs_package_name      = pick($docs_package_name, 'postgresql-docs')
        $plperl_package_name    = pick($plperl_package_name, 'postgresql-plperl')
        $plpython_package_name  = pick($plpython_package_name, 'postgresql-plpython')
        $service_name           = pick($service_name, 'postgresql')
        $bindir                 = pick($bindir, '/usr/bin')
        $datadir                = $facts['os']['name'] ? {
          'Amazon' => pick($datadir, "/var/lib/pgsql${package_version}/data"),
          default  => pick($datadir, '/var/lib/pgsql/data'),
        }
        $confdir                = pick($confdir, $datadir)
      } else {
        $client_package_name    = pick($client_package_name, "postgresql${package_version}")
        $server_package_name    = pick($server_package_name, "postgresql${package_version}-server")
        $contrib_package_name   = pick($contrib_package_name,"postgresql${package_version}-contrib")
        $devel_package_name     = pick($devel_package_name, "postgresql${package_version}-devel")
        $java_package_name      = pick($java_package_name, "postgresql${package_version}-jdbc")
        $docs_package_name      = pick($docs_package_name, "postgresql${package_version}-docs")
        $plperl_package_name    = pick($plperl_package_name, "postgresql${package_version}-plperl")
        $plpython_package_name  = pick($plpython_package_name, "postgresql${package_version}-plpython")
        $service_name           = $facts['os']['name'] ? {
          'Amazon' => pick($service_name, "postgresql${version_parts[0]}${version_parts[1]}"),
          default  => pick($service_name, "postgresql-${version}"),
        }
        $bindir                 = $facts['os']['name'] ? {
          'Amazon' => pick($bindir, '/usr/bin'),
          default  => pick($bindir, "/usr/pgsql-${version}/bin"),
        }
        $datadir                = $facts['os']['name'] ? {
          'Amazon' => pick($datadir, "/var/lib/pgsql${package_version}/data"),
          default  => pick($datadir, "/var/lib/pgsql/${version}/data"),
        }
        $confdir                = pick($confdir, $datadir)
        $postgresql_conf_mode   = pick($postgresql_conf_mode, '0600')
      }

      $service_reload = "systemctl reload ${service_name}"
      $service_status = pick($service_status, "systemctl status ${service_name}")

      $psql_path           = pick($psql_path, "${bindir}/psql")

      $perl_package_name   = pick($perl_package_name, 'perl-DBD-Pg')
      if $facts['os']['family'] == 'RedHat' and versioncmp($facts['os']['release']['major'], '8') >= 0 {
        $python_package_name = pick($python_package_name, 'python3-psycopg2')
      } else {
        $python_package_name = pick($python_package_name, 'python-psycopg2')
      }

      if $postgresql::globals::postgis_package_name {
        $postgis_package_name = $postgresql::globals::postgis_package_name
      } elsif $facts['os']['name'] == 'Fedora' {
        $postgis_package_name = 'postgis'
      } elsif $postgis_version and versioncmp($postgis_version, '2') < 0 {
        $postgis_package_name = "postgis${package_version}"
      } else {
        $postgis_package_name = "postgis2_${package_version}"
      }
    }

    'Archlinux': {
      $link_pg_config     = true
      $needs_initdb       = pick($needs_initdb, true)
      $user               = pick($user, 'postgres')
      $group              = pick($group, 'postgres')

      # Archlinux doesn't have a client-package but has a libs package which
      # pulls in postgresql server
      $client_package_name    = pick($client_package_name, 'postgresql-libs')
      $server_package_name    = pick($server_package_name, 'postgresql')
      $java_package_name      = pick($java_package_name, 'postgresql-jdbc')
      # Archlinux doesn't have develop packages
      $devel_package_name     = pick($devel_package_name, 'postgresql-devel')
      # Archlinux postgresql package provides plperl
      $plperl_package_name    = pick($plperl_package_name, 'undef')
      $plpython_package_name  = pick($plpython_package_name, 'undef')
      $service_name           = pick($service_name, 'postgresql')
      $bindir                 = pick($bindir, '/usr/bin')
      $datadir                = pick($datadir, '/var/lib/postgres/data')
      $confdir                = pick($confdir, $datadir)
      $psql_path              = pick($psql_path, "${bindir}/psql")

      $service_status         = pick($service_status, "systemctl status ${service_name}")
      $service_reload         = "systemctl reload ${service_name}"
      $python_package_name    = pick($python_package_name, 'python-psycopg2')
      # Archlinux does not have a perl::DBD::Pg package
      $perl_package_name      = pick($perl_package_name, 'undef')
    }

    'Debian': {
      $link_pg_config     = false
      $user               = pick($user, 'postgres')
      $group              = pick($group, 'postgres')

      $needs_initdb = pick($needs_initdb, $postgresql::globals::manage_package_repo == true)
      $service_name = pick($service_name, 'postgresql')

      $client_package_name    = pick($client_package_name, "postgresql-client-${version}")
      $server_package_name    = pick($server_package_name, "postgresql-${version}")
      if $postgis_version and versioncmp($postgis_version, '2') < 0 {
        $postgis_package_name = pick($postgis_package_name, "postgresql-${version}-postgis")
      } elsif $postgis_version and versioncmp($postgis_version, '3') >= 0 {
        $postgis_package_name = pick($postgis_package_name, "postgresql-${version}-postgis-3")
      } else {
        $postgis_package_name = pick($postgis_package_name, "postgresql-${version}-postgis-${postgis_version}")
      }
      $devel_package_name     = pick($devel_package_name, 'libpq-dev')
      $java_package_name      = pick($java_package_name, 'libpostgresql-jdbc-java')
      $perl_package_name      = pick($perl_package_name, 'libdbd-pg-perl')
      $plperl_package_name    = pick($plperl_package_name, "postgresql-plperl-${version}")
      $plpython_package_name  = pick($plpython_package_name, "postgresql-plpython-${version}")

      $_ubuntu_2204 = ($facts['os']['name'] == 'Ubuntu' and versioncmp($facts['os']['release']['full'], '22.04') >= 0)
      $_debian_12 = ($facts['os']['name'] == 'Debian' and versioncmp($facts['os']['release']['full'], '12') >= 0)

      if $_ubuntu_2204 or $_debian_12 {
        $python_package_name = pick($python_package_name, 'python3-psycopg2')
      } else {
        $python_package_name = pick($python_package_name, 'python-psycopg2')
      }

      $bindir                 = pick($bindir, "/usr/lib/postgresql/${version}/bin")
      $datadir                = pick($datadir, "/var/lib/postgresql/${version}/main")
      $confdir                = pick($confdir, "/etc/postgresql/${version}/main")
      $service_reload         = "systemctl reload ${service_name}"
      $service_status         = pick($service_status, "systemctl status ${service_name}")
      $psql_path              = pick($psql_path, '/usr/bin/psql')
      $postgresql_conf_mode   = pick($postgresql_conf_mode, '0644')
    }

    'Gentoo': {
      $user                = pick($user, 'postgres')
      $group               = pick($group, 'postgres')

      $client_package_name  = pick($client_package_name, 'UNSET')
      $server_package_name  = pick($server_package_name, 'postgresql')
      $devel_package_name   = pick_default($devel_package_name, undef)
      $java_package_name    = pick($java_package_name, 'jdbc-postgresql')
      $perl_package_name    = pick($perl_package_name, 'DBD-Pg')
      $plperl_package_name  = undef
      $python_package_name  = pick($python_package_name, 'psycopg')

      $service_name         = pick($service_name, "postgresql-${version}")
      $bindir               = pick($bindir, "/usr/lib/postgresql-${version}/bin")
      $datadir              = pick($datadir, "/var/lib/postgresql/${version}_data")
      $confdir              = pick($confdir, "/etc/postgresql-${version}")
      $service_status       = pick($service_status, "systemctl status ${service_name}")
      $service_reload       = "systemctl reload ${service_name}"
      $psql_path            = pick($psql_path, "${bindir}/psql")

      $needs_initdb         = pick($needs_initdb, true)
    }

    'FreeBSD': {
      $user                 = pick($user, 'postgres')
      $group                = pick($group, 'postgres')
      $datadir              = pick($datadir, "/var/db/postgres/data${version}")
      $link_pg_config       = true
      $client_package_name  = pick($client_package_name, "databases/postgresql${version}-client")
      $server_package_name  = pick($server_package_name, "databases/postgresql${version}-server")
      $contrib_package_name = pick($contrib_package_name, "databases/postgresql${version}-contrib")
      $devel_package_name   = pick($devel_package_name, 'databases/postgresql-libpqxx3')
      $java_package_name    = pick($java_package_name, 'databases/postgresql-jdbc')
      $perl_package_name    = pick($plperl_package_name, 'databases/p5-DBD-Pg')
      $plperl_package_name  = pick($plperl_package_name, "databases/postgresql${version}-plperl")
      $python_package_name  = pick($python_package_name, 'databases/py-psycopg2')

      $service_name         = pick($service_name, 'postgresql')
      $bindir               = pick($bindir, '/usr/local/bin')
      $confdir              = pick($confdir, $datadir)
      $service_status       = pick($service_status, "/usr/local/etc/rc.d/${service_name} onestatus")
      $service_reload       = "service ${service_name} reload"
      $psql_path            = pick($psql_path, "${bindir}/psql")

      $needs_initdb         = pick($needs_initdb, true)
    }

    'OpenBSD': {
      $user                = pick($user, '_postgresql')
      $group               = pick($group, '_postgresql')

      $client_package_name  = pick($client_package_name, 'postgresql-client')
      $server_package_name  = pick($server_package_name, 'postgresql-server')
      $contrib_package_name = pick($contrib_package_name, 'postgresql-contrib')
      $devel_package_name   = pick($devel_package_name, 'postgresql-client')
      $java_package_name    = pick($java_package_name, 'postgresql-jdbc')
      $perl_package_name    = pick($perl_package_name, 'databases/p5-DBD-Pg')
      $plperl_package_name  = undef
      $python_package_name  = pick($python_package_name, 'py-psycopg2')

      $service_name         = pick($service_name, 'postgresql')
      $bindir               = pick($bindir, '/usr/local/bin')
      $datadir              = pick($datadir, '/var/postgresql/data')
      $confdir              = pick($confdir, $datadir)
      $service_status       = pick($service_status, "/etc/rc.d/${service_name} check")
      $service_reload       = "/etc/rc.d/${service_name} reload"
      $psql_path            = pick($psql_path, "${bindir}/psql")

      $needs_initdb         = pick($needs_initdb, true)
    }

    'Suse': {
      $link_pg_config       = true
      $user                 = pick($user, 'postgres')
      $group                = pick($group, 'postgres')

      $client_package_name  = pick($client_package_name, "postgresql${version}")
      $server_package_name  = pick($server_package_name, "postgresql${version}-server")
      $contrib_package_name = pick($contrib_package_name, "postgresql${version}-contrib")
      $devel_package_name   = pick($devel_package_name, "postgresql${version}-devel")
      $java_package_name    = pick($java_package_name, "postgresql${version}-jdbc")
      $perl_package_name    = pick($plperl_package_name, 'perl-DBD-Pg')
      $plperl_package_name  = pick($plperl_package_name, "postgresql${version}-plperl")
      $python_package_name  = pick($python_package_name, 'python-psycopg2')

      $service_name         = pick($service_name, 'postgresql')
      $bindir               = pick($bindir, "/usr/lib/postgresql${version}/bin")
      $datadir              = pick($datadir, '/var/lib/pgsql/data')
      $confdir              = pick($confdir, $datadir)
      $service_status       = pick($service_status, "systemctl status ${service_name}")
      $service_reload       = "systemctl reload ${service_name}"
      $psql_path            = pick($psql_path, "${bindir}/psql")

      $needs_initdb         = pick($needs_initdb, true)
    }

    default: {
      $link_pg_config       = true
      $psql_path            = pick($psql_path, "${bindir}/psql")

      # Since we can't determine defaults on our own, we rely on users setting
      # parameters with the postgresql::globals class. Here we are checking
      # that the mandatory minimum is set for the module to operate.
      $err_prefix = "Module ${module_name} does not provide defaults for osfamily: ${facts['os']['family']} operatingsystem: ${facts['os']['name']}; please specify a value for ${module_name}::globals::" # lint:ignore:140chars
      if ($needs_initdb == undef) { fail("${err_prefix}needs_initdb") }
      if ($service_name == undef) { fail("${err_prefix}service_name") }
      if ($client_package_name == undef) { fail("${err_prefix}client_package_name") }
      if ($server_package_name == undef) { fail("${err_prefix}server_package_name") }
      if ($bindir == undef) { fail("${err_prefix}bindir") }
      if ($datadir == undef) { fail("${err_prefix}datadir") }
      if ($confdir == undef) { fail("${err_prefix}confdir") }
    }
  }

  if($data_checksums and versioncmp($version, '9.3') < 0) {
    fail('data_checksums require version 9.3 or greater')
  }

  $validcon_script_path = pick($validcon_script_path, '/usr/local/bin/validate_postgresql_connection.sh')
  $initdb_path          = pick($initdb_path, "${bindir}/initdb")
  $pg_hba_conf_path     = pick($pg_hba_conf_path, "${confdir}/pg_hba.conf")
  $pg_hba_conf_defaults = pick($pg_hba_conf_defaults, true)
  $pg_ident_conf_path   = pick($pg_ident_conf_path, "${confdir}/pg_ident.conf")
  $postgresql_conf_path = pick($postgresql_conf_path, "${confdir}/postgresql.conf")
  $recovery_conf_path   = pick($recovery_conf_path, "${datadir}/recovery.conf")
  $default_database     = pick($default_database, 'postgres')
}