Skip to content

Commit f1ee0e1

Browse files
authored
Merge pull request #1399 from SimonHoenscheid/shoenscheid_epp_templates
convert ERB templates to EPP
2 parents d4af1d8 + 04d61cb commit f1ee0e1

13 files changed

+184
-81
lines changed

manifests/server/instance/systemd.pp

+6-1
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,12 @@
1919
unit => "${service_name}.service",
2020
owner => 'root',
2121
group => 'root',
22-
content => template('postgresql/systemd-override.erb'),
22+
content => epp('postgresql/systemd-override.conf.epp', {
23+
port => $port,
24+
datadir => $datadir,
25+
extra_systemd_config => $extra_systemd_config,
26+
}
27+
),
2328
notify => Class['postgresql::server::service'],
2429
before => Class['postgresql::server::reload'],
2530
}

manifests/server/pg_hba_rule.pp

+21-8
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

+16-4
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
$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
}

manifests/server/recovery.pp

+22-3
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
# lint:ignore:140chars
12
# @summary This resource manages the parameters that applies to the recovery.conf template.
23
#
34
# @note
@@ -22,6 +23,7 @@
2223
# @param trigger_file Specifies a trigger file whose presence ends recovery in the standby.
2324
# @param recovery_min_apply_delay This parameter allows you to delay recovery by a fixed period of time, measured in milliseconds if no unit is specified.
2425
# @param target Provides the target for the rule, and is generally an internal only property. Use with caution.
26+
# lint:endignore:140chars
2527
define postgresql::server::recovery (
2628
$restore_command = undef,
2729
$archive_cleanup_command = undef,
@@ -41,14 +43,14 @@
4143
$target = $postgresql::server::recovery_conf_path
4244
) {
4345
if $postgresql::server::manage_recovery_conf == false {
44-
fail('postgresql::server::manage_recovery_conf has been disabled, so this resource is now unused and redundant, either enable that option or remove this resource from your manifests')
46+
fail('postgresql::server::manage_recovery_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
4547
} else {
4648
if($restore_command == undef and $archive_cleanup_command == undef and $recovery_end_command == undef
4749
and $recovery_target_name == undef and $recovery_target_time == undef and $recovery_target_xid == undef
4850
and $recovery_target_inclusive == undef and $recovery_target == undef and $recovery_target_timeline == undef
4951
and $pause_at_recovery_target == undef and $standby_mode == undef and $primary_conninfo == undef
5052
and $primary_slot_name == undef and $trigger_file == undef and $recovery_min_apply_delay == undef) {
51-
fail('postgresql::server::recovery use this resource but do not pass a parameter will avoid creating the recovery.conf, because it makes no sense.')
53+
fail('postgresql::server::recovery use this resource but do not pass a parameter will avoid creating the recovery.conf, because it makes no sense.') # lint:ignore:140chars
5254
}
5355

5456
concat { $target:
@@ -63,7 +65,24 @@
6365
# Create the recovery.conf content
6466
concat::fragment { "${name}-recovery.conf":
6567
target => $target,
66-
content => template('postgresql/recovery.conf.erb'),
68+
content => epp('postgresql/recovery.conf.epp', {
69+
restore_command => $restore_command,
70+
archive_cleanup_command => $archive_cleanup_command,
71+
recovery_end_command => $recovery_end_command,
72+
recovery_target_name => $recovery_target_name,
73+
recovery_target_time => $recovery_target_time,
74+
recovery_target_xid => $recovery_target_xid,
75+
recovery_target_inclusive => $recovery_target_inclusive,
76+
recovery_target => $recovery_target,
77+
recovery_target_timeline => $recovery_target_timeline,
78+
pause_at_recovery_target => $pause_at_recovery_target,
79+
standby_mode => $standby_mode,
80+
primary_conninfo => $primary_conninfo,
81+
primary_slot_name => $primary_slot_name,
82+
trigger_file => $trigger_file,
83+
recovery_min_apply_delay => $recovery_min_apply_delay,
84+
}
85+
),
6786
}
6887
}
6988
}

templates/pg_dump.sh.epp

+13
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,16 @@
1+
<%- |
2+
Boolean $compress,
3+
Array $databases,
4+
Optional[String[1]] $db_user,
5+
Boolean $delete_before_dump,
6+
String[1] $dir,
7+
Enum['plain','custom','directory','tar'] $format,
8+
Array $optional_args,
9+
Optional[String[1]] $post_script,
10+
Optional[String[1]] $pre_script,
11+
Integer[0] $rotate,
12+
Stdlib::Absolutepath $success_file_path,
13+
| -%>
114
<%- if $facts['kernel'] == 'Linux' { -%>
215
#!/bin/bash
316
<%- } else { -%>

templates/pg_hba_rule.conf

-5
This file was deleted.

templates/pg_hba_rule.conf.epp

+15
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
<%- |
2+
String[1] $name,
3+
String[1] $description,
4+
Variant[String, Integer] $order,
5+
Postgresql::Pg_hba_rule_type $type,
6+
String[1] $database,
7+
String[1] $user,
8+
Optional[Postgresql::Pg_hba_rule_address] $address,
9+
String[1] $auth_method,
10+
Optional[String] $auth_option,
11+
| -%>
12+
# Rule Name: <%= $name %>
13+
# Description: <%= $description %>
14+
# Order: <%= $order %>
15+
<%= $type %> <%= $database %> <%= $user %> <%= $address %> <%= $auth_method %> <%= $auth_option %>

templates/pg_ident_rule.conf

-5
This file was deleted.

templates/pg_ident_rule.conf.epp

+12
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
<%- |
2+
String[1] $name,
3+
String[1] $description,
4+
String[1] $order,
5+
String[1] $map_name,
6+
String[1] $system_username,
7+
String[1] $database_username,
8+
| -%>
9+
# Rule Name: <%= $name %>
10+
# Description: <%= $description %>
11+
# Order: <%= $order %>
12+
<%= $map_name %> <%= $system_username %> <%= $database_username %>

templates/recovery.conf.epp

+64
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
<%- |
2+
Optional[String] $restore_command,
3+
Optional[String[1]] $archive_cleanup_command,
4+
Optional[String[1]] $recovery_end_command,
5+
Optional[String[1]] $recovery_target_name,
6+
Optional[String[1]] $recovery_target_time,
7+
Optional[String[1]] $recovery_target_xid,
8+
Optional[Boolean] $recovery_target_inclusive,
9+
Optional[String[1]] $recovery_target,
10+
Optional[String[1]] $recovery_target_timeline,
11+
Optional[Boolean] $pause_at_recovery_target,
12+
Optional[String[1]] $standby_mode,
13+
Optional[String[1]] $primary_conninfo,
14+
Optional[String[1]] $primary_slot_name,
15+
Optional[String[1]] $trigger_file,
16+
Optional[Integer] $recovery_min_apply_delay,
17+
| -%>
18+
<% if $restore_command { -%>
19+
restore_command = '<%= $restore_command %>'
20+
<% } -%>
21+
<% if $archive_cleanup_command { -%>
22+
archive_cleanup_command = '<%= $archive_cleanup_command %>'
23+
<% } -%>
24+
<% if $recovery_end_command { -%>
25+
recovery_end_command = '<%= $recovery_end_command %>'
26+
<% } -%>
27+
28+
<% if $recovery_target_name { -%>
29+
recovery_target_name = '<%= $recovery_target_name %>'
30+
<% } -%>
31+
<% if $recovery_target_time { -%>
32+
recovery_target_time = '<%= $recovery_target_time %>'
33+
<% } -%>
34+
<% if $recovery_target_xid { -%>
35+
recovery_target_xid = '<%= $recovery_target_xid %>'
36+
<% } -%>
37+
<% if $recovery_target_inclusive { -%>
38+
recovery_target_inclusive = <%= $recovery_target_inclusive %>
39+
<% } -%>
40+
<% if $recovery_target { -%>
41+
recovery_target = '<%= $recovery_target %>'
42+
<% } -%>
43+
<% if $recovery_target_timeline { -%>
44+
recovery_target_timeline = '<%= $recovery_target_timeline %>'
45+
<% } -%>
46+
<% if $pause_at_recovery_target { -%>
47+
pause_at_recovery_target = <%= $pause_at_recovery_target %>
48+
<% } -%>
49+
50+
<% if $standby_mode { -%>
51+
standby_mode = <%= $standby_mode %>
52+
<% } -%>
53+
<% if $primary_conninfo { -%>
54+
primary_conninfo = '<%= $primary_conninfo %>'
55+
<% } -%>
56+
<% if $primary_slot_name { -%>
57+
primary_slot_name = '<%= $primary_slot_name %>'
58+
<% } -%>
59+
<% if $trigger_file { -%>
60+
trigger_file = '<%= $trigger_file %>'
61+
<% } -%>
62+
<% if $recovery_min_apply_delay { -%>
63+
recovery_min_apply_delay = <%= $recovery_min_apply_delay %>
64+
<% } -%>

templates/recovery.conf.erb

-47
This file was deleted.

templates/systemd-override.conf.epp

+15
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
<%- |
2+
Variant[String[1], Stdlib::Port] $port,
3+
Stdlib::Absolutepath $datadir,
4+
Optional[String[1]] $extra_systemd_config,
5+
| -%>
6+
[Service]
7+
Environment=PGPORT=<%= $port %>
8+
<%- if $facts['os']['family'] == 'Gentoo' { -%>
9+
Environment=DATA_DIR=<%= $datadir %>
10+
<%- } else { -%>
11+
Environment=PGDATA=<%= $datadir %>
12+
<%- } -%>
13+
<% if $extra_systemd_config { -%>
14+
<%= $extra_systemd_config %>
15+
<% } -%>

templates/systemd-override.erb

-8
This file was deleted.

0 commit comments

Comments
 (0)