|
9 | 9 | # version may be set to a specific version, in which case the extension is updated using ALTER EXTENSION "extension" UPDATE TO 'version'
|
10 | 10 | # eg. If extension is set to postgis and version is set to 2.3.3, this will apply the SQL ALTER EXTENSION "postgis" UPDATE TO '2.3.3' to this database only.
|
11 | 11 | # version may be omitted, in which case no ALTER EXTENSION... SQL is applied, and the version will be left unchanged.
|
12 |
| -# |
| 12 | +# |
13 | 13 | # @param ensure Specifies whether to activate or deactivate the extension. Valid options: 'present' or 'absent'.
|
14 | 14 | # @param package_name Specifies a package to install prior to activating the extension.
|
15 | 15 | # @param package_ensure Overrides default package deletion behavior. By default, the package specified with package_name is installed when the extension is activated and removed when the extension is deactivated. To override this behavior, set the ensure value for the package.
|
| 16 | +# @param port Port to use when connecting. |
16 | 17 | # @param connect_settings Specifies a hash of environment variables used when connecting to a remote server.
|
17 | 18 | # @param database_resource_name Specifies the resource name of the DB being managed. Defaults to the parameter $database, if left blank.
|
18 | 19 | define postgresql::server::extension (
|
|
23 | 24 | String[1] $ensure = 'present',
|
24 | 25 | $package_name = undef,
|
25 | 26 | $package_ensure = undef,
|
| 27 | + Optional[Integer] $port = undef, |
26 | 28 | $connect_settings = postgresql::default('default_connect_settings'),
|
27 | 29 | $database_resource_name = $database,
|
28 | 30 | ) {
|
|
33 | 35 | case $ensure {
|
34 | 36 | 'present': {
|
35 | 37 | $command = "CREATE EXTENSION \"${extension}\""
|
36 |
| - $unless_mod = '' |
| 38 | + $unless_mod = undef |
37 | 39 | $package_require = []
|
38 | 40 | $package_before = Postgresql_psql["${database}: ${command}"]
|
39 | 41 | }
|
|
57 | 59 | }
|
58 | 60 | }
|
59 | 61 |
|
| 62 | + # |
| 63 | + # Port, order of precedence: $port parameter, $connect_settings[PGPORT], $postgresql::server::port |
| 64 | + # |
| 65 | + if $port != undef { |
| 66 | + $port_override = $port |
| 67 | + } elsif $connect_settings != undef and has_key( $connect_settings, 'PGPORT') { |
| 68 | + $port_override = undef |
| 69 | + } else { |
| 70 | + $port_override = $postgresql::server::port |
| 71 | + } |
| 72 | + |
60 | 73 | postgresql_psql { "${database}: ${command}":
|
61 | 74 |
|
62 | 75 | psql_user => $user,
|
|
65 | 78 | connect_settings => $connect_settings,
|
66 | 79 |
|
67 | 80 | db => $database,
|
| 81 | + port => $port_override, |
68 | 82 | command => $command,
|
69 | 83 | unless => "SELECT 1 WHERE ${unless_mod}EXISTS (SELECT 1 FROM pg_extension WHERE extname = '${extension}')",
|
70 | 84 | }
|
|
90 | 104 | psql_path => $psql_path,
|
91 | 105 | connect_settings => $connect_settings,
|
92 | 106 | db => $database,
|
| 107 | + port => $port_override, |
93 | 108 | require => Postgresql_psql["${database}: ${command}"],
|
94 | 109 | }
|
95 | 110 |
|
|
119 | 134 | }
|
120 | 135 | postgresql_psql { "${database}: ${alter_extension_sql}":
|
121 | 136 | db => $database,
|
| 137 | + port => $port_override, |
122 | 138 | psql_user => $user,
|
123 | 139 | psql_group => $group,
|
124 | 140 | psql_path => $psql_path,
|
|
0 commit comments