Skip to content

Commit 2e9a9c4

Browse files
authored
Merge branch 'main' into CONT-361-Syntax_update
2 parents 621f337 + 54602cd commit 2e9a9c4

23 files changed

+274
-294
lines changed

.fixtures.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,3 +10,4 @@ fixtures:
1010
puppet_agent: 'https://github.com/puppetlabs/puppetlabs-puppet_agent.git'
1111
stdlib: "https://github.com/puppetlabs/puppetlabs-stdlib.git"
1212
yumrepo_core: "https://github.com/puppetlabs/puppetlabs-yumrepo_core.git"
13+
systemd: "https://github.com/voxpupuli/puppet-systemd.git"

.github/workflows/mend.yml

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
name: "mend"
2+
3+
on:
4+
pull_request:
5+
branches:
6+
- "main"
7+
schedule:
8+
- cron: "0 0 * * *"
9+
workflow_dispatch:
10+
11+
jobs:
12+
13+
mend:
14+
uses: "puppetlabs/cat-github-actions/.github/workflows/mend_ruby.yml@main"
15+
secrets: "inherit"

manifests/params.pp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@
2626
$package_ensure = 'present'
2727
$module_workdir = pick($module_workdir,'/tmp')
2828
$password_encryption = undef
29-
$extra_systemd_config = ''
29+
$extra_systemd_config = undef
3030
$manage_datadir = true
3131
$manage_logdir = true
3232
$manage_xlogdir = true

manifests/server/config_entry.pp

Lines changed: 1 addition & 72 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
#
33
# @param ensure Removes an entry if set to 'absent'.
44
# @param value Defines the value for the setting.
5-
# @param path Path for postgresql.conf
5+
# @param path Path for postgresql.conf
66
#
77
define postgresql::server::config_entry (
88
Enum['present', 'absent'] $ensure = 'present',
@@ -70,10 +70,6 @@
7070
'max_pred_locks_per_transaction' => undef,
7171
}
7272

73-
Exec {
74-
logoutput => 'on_failure',
75-
}
76-
7773
if ! ($name in $requires_restart_until and (
7874
! $requires_restart_until[$name] or
7975
versioncmp($postgresql::server::_version, $requires_restart_until[$name]) < 0
@@ -91,73 +87,6 @@
9187
}
9288
}
9389

94-
# We have to handle ports and the data directory in a weird and
95-
# special way. On early Debian and Ubuntu and RHEL we have to ensure
96-
# we stop the service completely. On RHEL 7 we either have to create
97-
# a systemd override for the port or update the sysconfig file, but this
98-
# is managed for us in postgresql::server::config.
99-
if $facts['os']['name'] == 'Debian' or $facts['os']['name'] == 'Ubuntu' {
100-
if $name == 'data_directory' {
101-
$stop_command = ['service', $postgresql::server::service_name, 'stop']
102-
$stop_onlyif = ['service', $postgresql::server::service_name, 'status']
103-
$stop_unless = [['grep', "data_directory = '${value}'", $postgresql::server::postgresql_conf_path]]
104-
exec { "postgresql_stop_${name}":
105-
command => $stop_command,
106-
onlyif => $stop_onlyif,
107-
unless => $stop_unless,
108-
path => '/usr/sbin:/sbin:/bin:/usr/bin:/usr/local/bin',
109-
before => Postgresql_conf[$name],
110-
}
111-
}
112-
} elsif $facts['os']['family'] == 'RedHat' and versioncmp($facts['os']['release']['major'], '7') < 0 {
113-
if $name == 'port' {
114-
# We need to force postgresql to stop before updating the port
115-
# because puppet becomes confused and is unable to manage the
116-
# service appropriately.
117-
$stop_command = ['service', $postgresql::server::service_name, 'stop']
118-
$stop_onlyif = ['service', $postgresql::server::service_name, 'status']
119-
$stop_unless = "grep 'PGPORT=${shell_escape($value)}' /etc/sysconfig/pgsql/postgresql"
120-
exec { "postgresql_stop_${name}":
121-
command => $stop_command,
122-
onlyif => $stop_onlyif,
123-
unless => $stop_unless,
124-
path => '/sbin:/bin:/usr/bin:/usr/local/bin',
125-
require => File['/etc/sysconfig/pgsql/postgresql'],
126-
}
127-
-> augeas { 'override PGPORT in /etc/sysconfig/pgsql/postgresql':
128-
lens => 'Shellvars.lns',
129-
incl => '/etc/sysconfig/pgsql/postgresql',
130-
context => '/files/etc/sysconfig/pgsql/postgresql',
131-
changes => "set PGPORT ${value}",
132-
require => File['/etc/sysconfig/pgsql/postgresql'],
133-
notify => Class['postgresql::server::service'],
134-
before => Class['postgresql::server::reload'],
135-
}
136-
} elsif $name == 'data_directory' {
137-
# We need to force postgresql to stop before updating the data directory
138-
# otherwise init script breaks
139-
$stop_command = ['service', $postgresql::server::service_name, 'stop']
140-
$stop_onlyif = ['service', $postgresql::server::service_name, 'status']
141-
$stop_unless = [['grep', "PGDATA=${value}", '/etc/sysconfig/pgsql/postgresql']]
142-
exec { "postgresql_${name}":
143-
command => $stop_command,
144-
onlyif => $stop_onlyif,
145-
unless => $stop_unless,
146-
path => '/sbin:/bin:/usr/bin:/usr/local/bin',
147-
require => File['/etc/sysconfig/pgsql/postgresql'],
148-
}
149-
-> augeas { 'override PGDATA in /etc/sysconfig/pgsql/postgresql':
150-
lens => 'Shellvars.lns',
151-
incl => '/etc/sysconfig/pgsql/postgresql',
152-
context => '/files/etc/sysconfig/pgsql/postgresql',
153-
changes => "set PGDATA ${value}",
154-
require => File['/etc/sysconfig/pgsql/postgresql'],
155-
notify => Class['postgresql::server::service'],
156-
before => Class['postgresql::server::reload'],
157-
}
158-
}
159-
}
160-
16190
postgresql_conf { $name:
16291
ensure => $ensure,
16392
target => $target,

manifests/server/instance/config.pp

Lines changed: 6 additions & 69 deletions
Original file line numberDiff line numberDiff line change
@@ -217,25 +217,6 @@
217217
}
218218
}
219219

220-
# RedHat-based systems hardcode some PG* variables in the init script, and need to be overriden
221-
# in /etc/sysconfig/pgsql/postgresql. Create a blank file so we can manage it with augeas later.
222-
if $facts['os']['family'] == 'RedHat' and versioncmp($facts['os']['release']['major'], '7') < 0 {
223-
file { '/etc/sysconfig/pgsql/postgresql':
224-
ensure => file,
225-
replace => false,
226-
}
227-
228-
# The init script from the packages of the postgresql.org repository
229-
# sources an alternate sysconfig file.
230-
# I. e. /etc/sysconfig/pgsql/postgresql-9.3 for PostgreSQL 9.3
231-
# Link to the sysconfig file set by this puppet module
232-
file { "/etc/sysconfig/pgsql/postgresql-${version}":
233-
ensure => link,
234-
target => '/etc/sysconfig/pgsql/postgresql',
235-
require => File['/etc/sysconfig/pgsql/postgresql'],
236-
}
237-
}
238-
239220
if ($manage_pg_ident_conf == true) {
240221
concat { $pg_ident_conf_path:
241222
owner => $user,
@@ -246,58 +227,14 @@
246227
}
247228
}
248229
# lint:ignore:140chars
249-
# RHEL 7 and 8 both support drop-in files for systemd units. The old include directive is deprecated and may be removed in future systemd releases.
250-
# Gentoo also supports drop-in files.
230+
# RHEL 7 and 8 both support drop-in files for systemd units. Gentoo also supports drop-in files.
231+
# Edit 02/2023 RHEL basedc Systems and Gentoo need Variables set for $PGPORT, $DATA_DIR or $PGDATA, thats what the drop-in file is for.
251232
# lint:endignore:140chars
252233
if $facts['os']['family'] in ['RedHat', 'Gentoo'] and $facts['service_provider'] == 'systemd' {
253-
# While Puppet 6.1 and newer can do a daemon-reload if needed, systemd
254-
# doesn't appear to report that correctly in all cases.
255-
# One such case seems to be when an overriding unit file is removed from /etc
256-
# and the original one from /lib *should* be used again.
257-
#
258-
# This can be removed when Puppet < 6.1 support is dropped *and* the file
259-
# old-systemd-override is removed.
260-
$systemd_command = ['systemctl', 'daemon-reload']
261-
exec { 'restart-systemd':
262-
command => $systemd_command,
263-
refreshonly => true,
264-
path => '/bin:/usr/bin:/usr/local/bin',
265-
before => Class['postgresql::server::service'],
266-
}
267-
268-
file {
269-
default:
270-
ensure => file,
271-
owner => root,
272-
group => root,
273-
notify => [Exec['restart-systemd'], Class['postgresql::server::service']],
274-
before => Class['postgresql::server::reload'];
275-
276-
'systemd-conf-dir':
277-
ensure => directory,
278-
path => "/etc/systemd/system/${service_name}.service.d";
279-
280-
# Template uses:
281-
# - $facts['os']['name']
282-
# - $facts['os']['release']['major']
283-
# - $service_name
284-
# - $port
285-
# - $datadir
286-
# - $extra_systemd_config
287-
'systemd-override':
288-
path => "/etc/systemd/system/${service_name}.service.d/${service_name}.conf",
289-
content => template('postgresql/systemd-override.erb'),
290-
require => File['systemd-conf-dir'];
291-
}
292-
293-
if $service_enable != 'mask' {
294-
# Remove old unit file to avoid conflicts
295-
file { 'old-systemd-override':
296-
ensure => absent,
297-
path => "/etc/systemd/system/${service_name}.service",
298-
notify => [Exec['restart-systemd'], Class['postgresql::server::service']],
299-
before => Class['postgresql::server::reload'],
300-
}
234+
postgresql::server::instance::systemd { $service_name:
235+
port => $port,
236+
datadir => $datadir,
237+
extra_systemd_config => $extra_systemd_config,
301238
}
302239
}
303240
}

manifests/server/instance/systemd.pp

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
# @summary This define handles systemd drop-in files for the postgres main instance (default) or additional instances
2+
# @param service_name Overrides the default PostgreSQL service name.
3+
# @param drop_in_ensure sets the Systemd drop-in file to present or absent
4+
# @api private
5+
define postgresql::server::instance::systemd (
6+
Variant[String[1], Stdlib::Port] $port,
7+
Stdlib::Absolutepath $datadir,
8+
Optional[String[1]] $extra_systemd_config = undef,
9+
String[1] $service_name = $name,
10+
Enum[present, absent] $drop_in_ensure = 'present',
11+
12+
) {
13+
# Template uses:
14+
# - $port
15+
# - $datadir
16+
# - $extra_systemd_config
17+
systemd::dropin_file { "${service_name}.conf":
18+
ensure => $drop_in_ensure,
19+
unit => "${service_name}.service",
20+
owner => 'root',
21+
group => 'root',
22+
content => epp('postgresql/systemd-override.conf.epp', {
23+
port => $port,
24+
datadir => $datadir,
25+
extra_systemd_config => $extra_systemd_config,
26+
}
27+
),
28+
notify => Class['postgresql::server::service'],
29+
before => Class['postgresql::server::reload'],
30+
}
31+
}

manifests/server/pg_hba_rule.pp

Lines changed: 21 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
# lint:ignore:140chars
12
# @summary This resource manages an individual rule that applies to the file defined in target.
23
#
34
# @param type Sets the type of rule.
@@ -10,13 +11,14 @@
1011
# @param order Sets an order for placing the rule in pg_hba.conf. This can be either a string or an integer. If it is an integer, it will be converted to a string by zero-padding it to three digits. E.g. 42 will be zero-padded to the string '042'. The pg_hba_rule fragments are sorted using the alpha sorting order. Default value: 150.
1112
# @param target Provides the target for the rule, and is generally an internal only property. Use with caution.
1213
# @param postgresql_version Manages pg_hba.conf without managing the entire PostgreSQL instance.
14+
# lint:endignore:140chars
1315
define postgresql::server::pg_hba_rule (
1416
Postgresql::Pg_hba_rule_type $type,
15-
String $database,
16-
String $user,
17-
String $auth_method,
17+
String[1] $database,
18+
String[1] $user,
19+
String[1] $auth_method,
1820
Optional[Postgresql::Pg_hba_rule_address] $address = undef,
19-
String $description = 'none',
21+
String[1] $description = 'none',
2022
Optional[String] $auth_option = undef,
2123
Variant[String, Integer] $order = 150,
2224

@@ -34,7 +36,7 @@
3436
}
3537

3638
if $manage_pg_hba_conf == false {
37-
fail('postgresql::server::manage_pg_hba_conf has been disabled, so this resource is now unused and redundant, either enable that option or remove this resource from your manifests')
39+
fail('postgresql::server::manage_pg_hba_conf has been disabled, so this resource is now unused and redundant, either enable that option or remove this resource from your manifests') # lint:ignore:140chars
3840
} else {
3941
if($type =~ /^host/ and $address == undef) {
4042
fail('You must specify an address property when type is host based')
@@ -48,7 +50,7 @@
4850
}
4951

5052
$allowed_auth_methods = $postgresql_version ? {
51-
'10' => ['trust', 'reject', 'scram-sha-256', 'md5', 'password', 'gss', 'sspi', 'ident', 'peer', 'ldap', 'radius', 'cert', 'pam', 'bsd'],
53+
'10' => ['trust', 'reject', 'scram-sha-256', 'md5', 'password', 'gss', 'sspi', 'ident', 'peer', 'ldap', 'radius', 'cert', 'pam', 'bsd'], # lint:ignore:140chars
5254
'9.6' => ['trust', 'reject', 'md5', 'password', 'gss', 'sspi', 'ident', 'peer', 'ldap', 'radius', 'cert', 'pam', 'bsd'],
5355
'9.5' => ['trust', 'reject', 'md5', 'password', 'gss', 'sspi', 'ident', 'peer', 'ldap', 'radius', 'cert', 'pam'],
5456
'9.4' => ['trust', 'reject', 'md5', 'password', 'gss', 'sspi', 'ident', 'peer', 'ldap', 'radius', 'cert', 'pam'],
@@ -60,7 +62,7 @@
6062
'8.3' => ['trust', 'reject', 'md5', 'crypt', 'password', 'gss', 'sspi', 'krb5', 'ident', 'ldap', 'pam'],
6163
'8.2' => ['trust', 'reject', 'md5', 'crypt', 'password', 'krb5', 'ident', 'ldap', 'pam'],
6264
'8.1' => ['trust', 'reject', 'md5', 'crypt', 'password', 'krb5', 'ident', 'pam'],
63-
default => ['trust', 'reject', 'scram-sha-256', 'md5', 'password', 'gss', 'sspi', 'krb5', 'ident', 'peer', 'ldap', 'radius', 'cert', 'pam', 'crypt', 'bsd']
65+
default => ['trust', 'reject', 'scram-sha-256', 'md5', 'password', 'gss', 'sspi', 'krb5', 'ident', 'peer', 'ldap', 'radius', 'cert', 'pam', 'crypt', 'bsd'] # lint:ignore:140chars
6466
}
6567

6668
assert_type(Enum[$allowed_auth_methods], $auth_method)
@@ -69,7 +71,18 @@
6971
$fragname = "pg_hba_rule_${name}"
7072
concat::fragment { $fragname:
7173
target => $target,
72-
content => template('postgresql/pg_hba_rule.conf'),
74+
content => epp('postgresql/pg_hba_rule.conf.epp', {
75+
name => $name,
76+
description => $description,
77+
order => $order,
78+
type => $type,
79+
database => $database,
80+
user => $user,
81+
address => $address,
82+
auth_method => $auth_method,
83+
auth_option => $auth_option,
84+
}
85+
),
7386
order => $_order,
7487
}
7588
}

manifests/server/pg_ident_rule.pp

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,12 @@
22
#
33
# @param map_name Sets the name of the user map that is used to refer to this mapping in pg_hba.conf.
44
# @param system_username Specifies the operating system user name (the user name used to connect to the database).
5-
# @param database_username Specifies the user name of the database user. The system_username is mapped to this user name.
6-
# @param description Sets a longer description for this rule if required. This description is placed in the comments above the rule in pg_ident.conf. Default value: 'none'.
5+
# @param database_username
6+
# Specifies the user name of the database user.
7+
# The system_username is mapped to this user name.
8+
# @param description
9+
# Sets a longer description for this rule if required.
10+
# This description is placed in the comments above the rule in pg_ident.conf.
711
# @param order Defines an order for placing the mapping in pg_ident.conf. Default value: 150.
812
# @param target Provides the target for the rule and is generally an internal only property. Use with caution.
913
define postgresql::server::pg_ident_rule (
@@ -18,13 +22,21 @@
1822
Variant[String[1], Stdlib::Absolutepath] $target = $postgresql::server::pg_ident_conf_path
1923
) {
2024
if $postgresql::server::manage_pg_ident_conf == false {
21-
fail('postgresql::server::manage_pg_ident_conf has been disabled, so this resource is now unused and redundant, either enable that option or remove this resource from your manifests')
25+
fail('postgresql::server::manage_pg_ident_conf has been disabled, so this resource is now unused and redundant, either enable that option or remove this resource from your manifests') # lint:ignore:140chars
2226
} else {
2327
# Create a rule fragment
2428
$fragname = "pg_ident_rule_${name}"
2529
concat::fragment { $fragname:
2630
target => $target,
27-
content => template('postgresql/pg_ident_rule.conf'),
31+
content => epp('postgresql/pg_ident_rule.conf.epp', {
32+
name => $name,
33+
description => $description,
34+
order => $order,
35+
map_name => $map_name,
36+
system_username => $system_username,
37+
database_username => $database_username,
38+
}
39+
),
2840
order => $order,
2941
}
3042
}

0 commit comments

Comments
 (0)