Skip to content

Commit 673e47e

Browse files
committed
Merge pull request puppetlabs#138 from kbarber/ticket/master/128-provide_more_custom_parameters_for_custom_packaging
Ticket/master/128 provide more custom parameters for custom packaging
2 parents cd31c71 + 5012893 commit 673e47e

File tree

15 files changed

+298
-126
lines changed

15 files changed

+298
-126
lines changed

README.md

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -164,6 +164,39 @@ This will set the default database locale for all databases created with this mo
164164
####`charset`
165165
This will set the default charset for all databases created with this module. On certain operating systems this will be used during the `template1` initialization as well so it becomes a default outside of the module as well. Defaults to `UTF8`.
166166

167+
####`datadir`
168+
This setting can be used to override the default postgresql data directory for the target platform. If not specified, the module will use whatever directory is the default for your OS distro.
169+
170+
####`confdir`
171+
This setting can be used to override the default postgresql configuration directory for the target platform. If not specified, the module will use whatever directory is the default for your OS distro.
172+
173+
####`bindir`
174+
This setting can be used to override the default postgresql binaries directory for the target platform. If not specified, the module will use whatever directory is the default for your OS distro.
175+
176+
####`client_package_name`
177+
This setting can be used to override the default postgresql client package name. If not specified, the module will use whatever package name is the default for your OS distro.
178+
179+
####`server_package_name`
180+
This setting can be used to override the default postgresql server package name. If not specified, the module will use whatever package name is the default for your OS distro.
181+
182+
####`devel_package_name`
183+
This setting can be used to override the default postgresql devel package name. If not specified, the module will use whatever package name is the default for your OS distro.
184+
185+
####`java_package_name`
186+
This setting can be used to override the default postgresql java package name. If not specified, the module will use whatever package name is the default for your OS distro.
187+
188+
####`service_name`
189+
This setting can be used to override the default postgresql service name. If not specified, the module will use whatever service name is the default for your OS distro.
190+
191+
####`user`
192+
This setting can be used to override the default postgresql super user and owner of postgresql related files in the file system. If not specified, the module will use the user name 'postgres'.
193+
194+
####`group`
195+
This setting can be used to override the default postgresql user group to be used for related files in the file system. If not specified, the module will use the group name 'postgres'.
196+
197+
####`run_initdb`
198+
This setting can be used to explicitly call the initdb operation after server package is installed and before the postgresql service is started. If not specified, the module will decide whether to call initdb or not depending on your OS distro.
199+
167200
###Class: postgresql::server
168201
Here are the options that you can set in the `config_hash` parameter of `postgresql::server`:
169202

lib/puppet/provider/postgresql_psql/ruby.rb

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,8 @@ def run_unless_sql_command(sql)
5151
end
5252

5353
def run_sql_command(sql)
54-
command = %{psql #{"-d #{resource[:db]}" if resource[:db]} -t -c "#{sql.gsub('"', '\"')}"}
54+
command = %{#{resource[:psql_path]} #{"-d #{resource[:db]}" if resource[:db]} -t -c "#{sql.gsub('"', '\"')}"}
55+
5556
if resource[:cwd]
5657
Dir.chdir resource[:cwd] do
5758
Puppet::Util::SUIDManager.run_and_capture(command, resource[:psql_user], resource[:psql_group])

lib/puppet/type/postgresql_psql.rb

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,11 @@ def sync(refreshing = false)
4949
desc "The name of the database to execute the SQL command against."
5050
end
5151

52+
newparam(:psql_path) do
53+
desc "The path to psql executable."
54+
defaultto("psql")
55+
end
56+
5257
newparam(:psql_user) do
5358
desc "The system user account under which the psql command should be executed."
5459
defaultto("postgres")

manifests/config/afterservice.pp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@
2828
# for pg_hba.conf.
2929
exec { 'set_postgres_postgrespw':
3030
# This command works w/no password because we run it as postgres system user
31-
command => "psql -c \"ALTER ROLE postgres PASSWORD '${postgres_password}'\"",
31+
command => "psql -c \"ALTER ROLE ${postgresql::params::user} PASSWORD '${postgres_password}'\"",
3232
user => $postgresql::params::user,
3333
group => $postgresql::params::group,
3434
logoutput => true,

manifests/database.pp

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,13 @@
2727
) {
2828
include postgresql::params
2929

30+
# Set the defaults for the postgresql_psql resource
31+
Postgresql_psql {
32+
psql_user => $postgresql::params::user,
33+
psql_group => $postgresql::params::group,
34+
psql_path => $postgresql::params::psql_path,
35+
}
36+
3037
# Optionally set the locale switch. Older versions of createdb may not accept
3138
# --locale, so if the parameter is undefined its safer not to pass it.
3239
if ($postgresql::params::version != '8.1') {
@@ -52,23 +59,20 @@
5259
postgresql_psql { "Check for existence of db '${dbname}'":
5360
command => 'SELECT 1',
5461
unless => "SELECT datname FROM pg_database WHERE datname='${dbname}'",
55-
cwd => $postgresql::params::datadir,
5662
require => Class['postgresql::server']
5763
} ~>
5864

5965
exec { $createdb_command :
6066
refreshonly => true,
61-
user => 'postgres',
62-
cwd => $postgresql::params::datadir,
67+
user => $postgresql::params::user,
6368
logoutput => on_failure,
6469
} ~>
6570

6671
# This will prevent users from connecting to the database unless they've been
6772
# granted privileges.
68-
postgresql_psql {"REVOKE ${public_revoke_privilege} ON DATABASE ${dbname} FROM public":
69-
db => 'postgres',
73+
postgresql_psql {"REVOKE ${public_revoke_privilege} ON DATABASE \"${dbname}\" FROM public":
74+
db => $postgresql::params::user,
7075
refreshonly => true,
71-
cwd => $postgresql::params::datadir,
7276
}
7377

7478
}

manifests/database_grant.pp

Lines changed: 14 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -25,16 +25,22 @@
2525
# in the modules or not.
2626

2727
define postgresql::database_grant(
28-
# TODO: mysql supports an array of privileges here. We should do that if we
29-
# port this to ruby.
30-
$privilege,
31-
$db,
32-
$role,
33-
$psql_db = 'postgres',
34-
$psql_user ='postgres'
28+
# TODO: mysql supports an array of privileges here. We should do that if we
29+
# port this to ruby.
30+
$privilege,
31+
$db,
32+
$role,
33+
$psql_db = $postgresql::params::user,
34+
$psql_user = $postgresql::params::user
3535
) {
3636
include postgresql::params
3737

38+
Postgresql_psql {
39+
psql_user => $postgresql::params::user,
40+
psql_group => $postgresql::params::group,
41+
psql_path => $postgresql::params::psql_path,
42+
}
43+
3844
# TODO: FIXME: only works on databases, due to using has_database_privilege
3945

4046
# TODO: this is a terrible hack; if they pass "ALL" as the desired privilege,
@@ -50,11 +56,9 @@
5056
default => $privilege,
5157
}
5258

53-
postgresql_psql {"GRANT ${privilege} ON database ${db} TO ${role}":
59+
postgresql_psql {"GRANT ${privilege} ON database \"${db}\" TO \"${role}\"":
5460
db => $psql_db,
5561
psql_user => $psql_user,
5662
unless => "SELECT 1 WHERE has_database_privilege('${role}', '${db}', '${unless_privilege}')",
57-
cwd => $postgresql::params::datadir,
5863
}
5964
}
60-

manifests/database_user.pp

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -38,12 +38,12 @@
3838
#
3939

4040
define postgresql::database_user(
41-
$password_hash,
42-
$createdb = false,
43-
$createrole = false,
44-
$db = 'postgres',
45-
$superuser = false,
46-
$user = $title
41+
$password_hash,
42+
$createdb = false,
43+
$createrole = false,
44+
$db = $postgresql::params::user,
45+
$superuser = false,
46+
$user = $title
4747
) {
4848
postgresql::role { $user:
4949
db => $db,

manifests/init.pp

Lines changed: 87 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
# For examples, see the files in the `tests` directory; in particular,
1111
# `/server-yum-postgresql-org.pp`.
1212
#
13+
# === Parameters
1314
#
1415
# [*version*]
1516
# The postgresql version to install. If not specified, the
@@ -26,15 +27,70 @@
2627
# set to `true`. It determines which package repository should
2728
# be used to install the postgres packages. Currently supported
2829
# values include `yum.postgresql.org`.
29-
#
3030
# [*locale*]
3131
# This setting defines the default locale for initdb and createdb
3232
# commands. This default to 'undef' which is effectively 'C'.
3333
# [*charset*]
3434
# Sets the default charset to be used for initdb and createdb.
3535
# Defaults to 'UTF8'.
36+
# [*datadir*]
37+
# This setting can be used to override the default postgresql
38+
# data directory for the target platform. If not specified, the
39+
# module will use whatever directory is the default for your
40+
# OS distro.
41+
# [*confdir*]
42+
# This setting can be used to override the default postgresql
43+
# configuration directory for the target platform. If not
44+
# specified, the module will use whatever directory is the
45+
# default for your OS distro.
46+
# [*bindir*]
47+
# This setting can be used to override the default postgresql
48+
# binaries directory for the target platform. If not
49+
# specified, the module will use whatever directory is the
50+
# default for your OS distro.
51+
# [*client_package_name*]
52+
# This setting can be used to override the default
53+
# postgresql client package name. If not specified, the module
54+
# will use whatever package name is the default for your
55+
# OS distro.
56+
# [*server_package_name*]
57+
# This setting can be used to override the default
58+
# postgresql server package name. If not specified, the module
59+
# will use whatever package name is the default for your
60+
# OS distro.
61+
# [*devel_package_name*]
62+
# This setting can be used to override the default
63+
# postgresql devel package name. If not specified, the module
64+
# will use whatever package name is the default for your
65+
# OS distro.
66+
# [*java_package_name*]
67+
# This setting can be used to override the default
68+
# postgresql java package name. If not specified, the module
69+
# will use whatever package name is the default for your
70+
# OS distro.
71+
# [*service_name*]
72+
# This setting can be used to override the default
73+
# postgresql service name. If not specified, the module
74+
# will use whatever service name is the default for your
75+
# OS distro.
76+
# [*user*]
77+
# This setting can be used to override the default
78+
# postgresql super user and owner of postgresql related files
79+
# in the file system. If not specified, the module will use
80+
# the user name 'postgres'.
81+
# [*group*]
82+
# This setting can be used to override the default
83+
# postgresql user group to be used for related files
84+
# in the file system. If not specified, the module will use
85+
# the group name 'postgres'.
86+
# [*run_initdb*]
87+
# This setting can be used to explicitly call the initdb
88+
# operation after server package is installed and before
89+
# the postgresql service is started. If not specified, the
90+
# module will decide whether to call initdb or not depending
91+
# on your OS distro.
3692
#
37-
# === Examples:
93+
# === Examples
3894
#
3995
# class { 'postgresql':
4096
# version => '9.2',
@@ -47,13 +103,36 @@
47103
$manage_package_repo = false,
48104
$package_source = undef,
49105
$locale = undef,
50-
$charset = 'UTF8'
106+
$charset = 'UTF8',
107+
$datadir = undef,
108+
$confdir = undef,
109+
$bindir = undef,
110+
$client_package_name = undef,
111+
$server_package_name = undef,
112+
$devel_package_name = undef,
113+
$java_package_name = undef,
114+
$service_name = undef,
115+
$user = undef,
116+
$group = undef,
117+
$run_initdb = undef
51118
) {
119+
52120
class { 'postgresql::params':
53-
version => $version,
54-
manage_package_repo => $manage_package_repo,
55-
package_source => $package_source,
56-
locale => $locale,
57-
charset => $charset,
121+
version => $version,
122+
manage_package_repo => $manage_package_repo,
123+
package_source => $package_source,
124+
locale => $locale,
125+
charset => $charset,
126+
custom_datadir => $datadir,
127+
custom_confdir => $confdir,
128+
custom_bindir => $bindir,
129+
custom_client_package_name => $client_package_name,
130+
custom_server_package_name => $server_package_name,
131+
custom_devel_package_name => $devel_package_name,
132+
custom_java_package_name => $java_package_name,
133+
custom_service_name => $service_name,
134+
custom_user => $user,
135+
custom_group => $group,
136+
run_initdb => $run_initdb,
58137
}
59138
}

manifests/initdb.pp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,9 +19,9 @@
1919
class postgresql::initdb(
2020
$datadir = $postgresql::params::datadir,
2121
$encoding = $postgresql::params::charset,
22-
$group = 'postgres',
22+
$group = $postgresql::params::group,
2323
$initdb_path = $postgresql::params::initdb_path,
24-
$user = 'postgres'
24+
$user = $postgresql::params::user
2525
) inherits postgresql::params {
2626
# Build up the initdb command.
2727
#

0 commit comments

Comments
 (0)