Skip to content
This repository was archived by the owner on Feb 13, 2024. It is now read-only.

Commit 9d12358

Browse files
committed
Merge pull request puppetlabs#43 from cprice-puppet/feature/master/support-non-default-versions
Feature/master/support non default versions
2 parents 5c9658a + 228e5c5 commit 9d12358

27 files changed

+302
-97
lines changed

Modulefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,5 +7,5 @@ summary 'PostgreSQL defined resource types'
77
license 'Apache'
88
project_page 'https://github.com/puppetlabs/puppet-postgresql/issues'
99

10-
dependency 'puppetlabs/stdlib', '3.x'
10+
dependency 'puppetlabs/stdlib', '>= 3.2.0'
1111
dependency 'puppetlabs/firewall', '>= 0.0.4'

Rakefile

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
#require 'puppetlabs_spec_helper/rake_tasks'
2+
require 'puppet-lint/tasks/puppet-lint'
3+
4+
PuppetLint.configuration.send("disable_80chars")

manifests/config.pp

Lines changed: 20 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -44,29 +44,29 @@
4444
$manage_redhat_firewall = $postgresql::params::manage_redhat_firewall
4545
) inherits postgresql::params {
4646

47-
# Basically, all this class needs to handle is passing parameters on
48-
# to the "beforeservice" and "afterservice" classes, and ensure
49-
# the proper ordering.
47+
# Basically, all this class needs to handle is passing parameters on
48+
# to the "beforeservice" and "afterservice" classes, and ensure
49+
# the proper ordering.
5050

51-
class { 'postgresql::config::beforeservice':
52-
ip_mask_deny_postgres_user => $ip_mask_deny_postgres_user,
53-
ip_mask_allow_all_users => $ip_mask_allow_all_users,
54-
listen_addresses => $listen_addresses,
55-
ipv4acls => $ipv4acls,
56-
ipv6acls => $ipv6acls,
57-
pg_hba_conf_path => $pg_hba_conf_path,
58-
postgresql_conf_path => $postgresql_conf_path,
59-
manage_redhat_firewall => $manage_redhat_firewall,
60-
}
51+
class { 'postgresql::config::beforeservice':
52+
ip_mask_deny_postgres_user => $ip_mask_deny_postgres_user,
53+
ip_mask_allow_all_users => $ip_mask_allow_all_users,
54+
listen_addresses => $listen_addresses,
55+
ipv4acls => $ipv4acls,
56+
ipv6acls => $ipv6acls,
57+
pg_hba_conf_path => $pg_hba_conf_path,
58+
postgresql_conf_path => $postgresql_conf_path,
59+
manage_redhat_firewall => $manage_redhat_firewall,
60+
}
6161

62-
class { 'postgresql::config::afterservice':
63-
postgres_password => $postgres_password,
64-
}
62+
class { 'postgresql::config::afterservice':
63+
postgres_password => $postgres_password,
64+
}
6565

66-
Class['postgresql::config'] ->
67-
Class['postgresql::config::beforeservice'] ->
68-
Service['postgresqld'] ->
69-
Class['postgresql::config::afterservice']
66+
Class['postgresql::config'] ->
67+
Class['postgresql::config::beforeservice'] ->
68+
Service['postgresqld'] ->
69+
Class['postgresql::config::afterservice']
7070

7171

7272
}

manifests/config/beforeservice.pp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,16 +34,17 @@
3434
# }
3535
#
3636
class postgresql::config::beforeservice(
37+
$pg_hba_conf_path,
38+
$postgresql_conf_path,
3739
$ip_mask_deny_postgres_user = $postgresql::params::ip_mask_deny_postgres_user,
3840
$ip_mask_allow_all_users = $postgresql::params::ip_mask_allow_all_users,
3941
$listen_addresses = $postgresql::params::listen_addresses,
4042
$ipv4acls = $postgresql::params::ipv4acls,
4143
$ipv6acls = $postgresql::params::ipv6acls,
42-
$pg_hba_conf_path = $postgresql::params::pg_hba_conf_path,
43-
$postgresql_conf_path = $postgresql::params::postgresql_conf_path,
4444
$manage_redhat_firewall = $postgresql::params::manage_redhat_firewall
4545
) inherits postgresql::params {
4646

47+
4748
File {
4849
owner => $postgresql::params::user,
4950
group => $postgresql::params::group,

manifests/database.pp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323
$dbname = $title,
2424
$charset = 'UTF8')
2525
{
26-
require postgresql::params
26+
include postgresql::params
2727

2828
if ($::postgres_default_version != '8.1') {
2929
$locale_option = '--locale=C'

manifests/devel.pp

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,10 +17,9 @@
1717
$package_ensure = 'present'
1818
) inherits postgresql::params {
1919

20-
require postgresql
21-
22-
package { 'postgresql_devel':
20+
package { 'postgresql-devel':
2321
ensure => $package_ensure,
2422
name => $package_name,
23+
tag => 'postgresql',
2524
}
2625
}

manifests/init.pp

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,23 +2,29 @@
22
#
33
# This class installs postgresql client software.
44
#
5-
# Parameters:
6-
# [*client_package_name*] - The name of the postgresql client package.
5+
# *Note* don't forget to make sure to add any necessary yum or apt
6+
# repositories if specifying a custom version.
77
#
8+
# Parameters:
9+
# [*version*] - The postgresql version to install.
10+
# [*package_name*] - The name of the postgresql client package.
11+
# [*ensure*] - the ensure parameter passed to the postgresql client package resource
812
# Actions:
913
#
1014
# Requires:
1115
#
1216
# Sample Usage:
1317
#
1418
class postgresql (
19+
$version = $::postgres_default_version,
1520
$package_name = $postgresql::params::client_package_name,
1621
$package_ensure = 'present'
1722
) inherits postgresql::params {
1823

19-
package { 'postgresql_client':
24+
package { 'postgresql-client':
2025
ensure => $package_ensure,
2126
name => $package_name,
27+
tag => 'postgresql',
2228
}
2329

2430
}

manifests/initdb.pp

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,12 +21,11 @@
2121
$encoding = 'UTF8',
2222
$group = 'postgres',
2323
$initdb_path = $postgresql::params::initdb_path,
24-
$options = '',
2524
$user = 'postgres'
2625
) inherits postgresql::params {
2726

2827
$initdb_command = "${initdb_path} --encoding '${encoding}' --pgdata '${datadir}'"
29-
28+
3029
exec { $initdb_command:
3130
creates => "${datadir}/PG_VERSION",
3231
user => $user,
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
class postgresql::package_source::yum_postgresql_org(
2+
$version
3+
) {
4+
5+
$version_parts = split($version, '[.]')
6+
$package_version = "${version_parts[0]}${version_parts[1]}"
7+
8+
file { "/etc/pki/rpm-gpg/RPM-GPG-KEY-PGDG-${package_version}":
9+
source => "puppet:///modules/postgresql_tests/RPM-GPG-KEY-PGDG-${package_version}"
10+
} ->
11+
12+
yumrepo { "yum.postgresql.org":
13+
descr => "PostgreSQL ${version} \$releasever - \$basearch",
14+
baseurl => "http://yum.postgresql.org/${version}/redhat/rhel-\$releasever-\$basearch",
15+
enabled => 1,
16+
gpgcheck => 1,
17+
gpgkey => "file:///etc/pki/rpm-gpg/RPM-GPG-KEY-PGDG-${package_version}",
18+
}
19+
20+
Yumrepo["yum.postgresql.org"] -> Package<|tag == 'postgresql'|>
21+
22+
}

manifests/params.pp

Lines changed: 89 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,28 @@
1010
#
1111
# Sample Usage:
1212
#
13-
class postgresql::params {
13+
14+
# TODO: add real docs
15+
16+
# This class allows you to use a newer version of postgres, rather than your
17+
# system's default version.
18+
#
19+
# If you want to do that, note that it is important that you use the '->',
20+
# or a before/require metaparameter to make sure that the `params`
21+
# class is evaluated before any of the other classes in the module.
22+
#
23+
# Also note that this class includes the ability to automatically manage
24+
# the yumrepo resource. If you'd prefer to manage the repo yourself, simply pass
25+
# 'false' or omit the 'manage_repo' parameter--it defaults to 'false'. You will
26+
# still need to use the 'params' class to specify the postgres version
27+
# number, though, in order for the other classes to be able to find the
28+
# correct paths to the postgres dirs.
29+
30+
class postgresql::params(
31+
$version = $::postgres_default_version,
32+
$manage_package_repo = false,
33+
$package_source = undef,
34+
) {
1435
$user = 'postgres'
1536
$group = 'postgres'
1637
$ip_mask_deny_postgres_user = '0.0.0.0/0'
@@ -21,6 +42,32 @@
2142
# TODO: figure out a way to make this not platform-specific
2243
$manage_redhat_firewall = false
2344

45+
46+
if ($manage_package_repo) {
47+
case $::osfamily {
48+
'RedHat': {
49+
$rh_pkg_source = pick($package_source, 'yum.postgresql.org')
50+
51+
case $rh_pkg_source {
52+
'yum.postgresql.org': {
53+
class { "postgresql::package_source::yum_postgresql_org":
54+
version => $version
55+
}
56+
}
57+
58+
default: {
59+
fail("Unsupported package source '${rh_pkg_source}' for ${::osfamily} OS family. Currently the only supported source is 'yum.postgresql.org'")
60+
}
61+
}
62+
}
63+
64+
default: {
65+
fail("Unsupported osfamily: ${::osfamily} operatingsystem: ${::operatingsystem}, module ${module_name} currently only supports osfamily RedHat and Debian")
66+
}
67+
}
68+
}
69+
70+
2471
# This is a bit hacky, but if the puppet nodes don't have pluginsync enabled,
2572
# they will fail with a not-so-helpful error message. Here we are explicitly
2673
# verifying that the custom fact exists (which implies that pluginsync is
@@ -39,25 +86,43 @@
3986

4087
case $::osfamily {
4188
'RedHat': {
42-
$service_name = 'postgresql'
43-
$client_package_name = 'postgresql'
44-
$server_package_name = 'postgresql-server'
45-
$devel_package_name = 'postgresql-devel'
4689
$needs_initdb = true
47-
$initdb_path = '/usr/bin/initdb'
48-
$createdb_path = '/usr/bin/createdb'
49-
$psql_path = '/usr/bin/psql'
50-
$datadir = '/var/lib/pgsql/data/'
51-
$pg_hba_conf_path = '/var/lib/pgsql/data/pg_hba.conf'
52-
$postgresql_conf_path = '/var/lib/pgsql/data/postgresql.conf'
5390
$firewall_supported = true
5491
$persist_firewall_command = '/sbin/iptables-save > /etc/sysconfig/iptables'
92+
93+
if $version == $::postgres_default_version {
94+
$client_package_name = 'postgresql'
95+
$server_package_name = 'postgresql-server'
96+
$devel_package_name = 'postgresql-devel'
97+
$service_name = 'postgresql'
98+
$bindir = '/usr/bin'
99+
$datadir = '/var/lib/pgsql/data'
100+
$confdir = $datadir
101+
} else {
102+
$version_parts = split($version, '[.]')
103+
$package_version = "${version_parts[0]}${version_parts[1]}"
104+
$client_package_name = "postgresql${package_version}"
105+
$server_package_name = "postgresql${package_version}-server"
106+
$devel_package_name = "postgresql${package_version}-devel"
107+
$service_name = "postgresql-${version}"
108+
$bindir = "/usr/pgsql-${version}/bin"
109+
$datadir = "/var/lib/pgsql/${version}/data"
110+
$confdir = $datadir
111+
}
112+
113+
$service_status = undef
55114
}
56115

57116
'Debian': {
117+
$needs_initdb = false
118+
$firewall_supported = false
119+
# TODO: not exactly sure yet what the right thing to do for Debian/Ubuntu is.
120+
#$persist_firewall_command = '/sbin/iptables-save > /etc/iptables/rules.v4'
121+
122+
58123
case $::operatingsystem {
59124
'Debian': {
60-
$service_name = 'postgresql'
125+
$service_name = 'postgresql'
61126
}
62127

63128
'Ubuntu': {
@@ -69,27 +134,23 @@
69134
}
70135
}
71136

72-
$client_package_name = 'postgresql-client'
73-
$server_package_name = 'postgresql'
74-
$devel_package_name = 'libpq-dev'
75-
$needs_initdb = false
76-
$initdb_path = "/usr/lib/postgresql/${::postgres_default_version}/bin/initdb"
77-
$createdb_path = "/usr/lib/postgresql/${::postgres_default_version}/bin/createdb"
78-
$psql_path = "/usr/lib/postgresql/${::postgres_default_version}/bin/psql"
79-
$datadir = "/var/lib/postgresql/${::postgres_default_version}/main"
80-
$pg_hba_conf_path = "/etc/postgresql/${::postgres_default_version}/main/pg_hba.conf"
81-
$postgresql_conf_path = "/etc/postgresql/${::postgres_default_version}/main/postgresql.conf"
82-
$firewall_supported = false
83-
$service_status = "/etc/init.d/${service_name} status | /bin/egrep -q 'Running clusters: .+'"
84-
# TODO: not exactly sure yet what the right thing to do for Debian/Ubuntu is.
85-
#$persist_firewall_command = '/sbin/iptables-save > /etc/iptables/rules.v4'
86-
137+
$client_package_name = 'postgresql-client'
138+
$server_package_name = 'postgresql'
139+
$devel_package_name = 'libpq-dev'
140+
$bindir = "/usr/lib/postgresql/${::postgres_default_version}/bin"
141+
$datadir = "/var/lib/postgresql/${::postgres_default_version}/main"
142+
$confdir = "/etc/postgresql/${::postgres_default_version}/main"
143+
$service_status = "/etc/init.d/${service_name} status | /bin/egrep -q 'Running clusters: .+'"
87144
}
88145

89-
90146
default: {
91147
fail("Unsupported osfamily: ${::osfamily} operatingsystem: ${::operatingsystem}, module ${module_name} currently only supports osfamily RedHat and Debian")
92148
}
93149
}
94150

151+
$initdb_path = "${bindir}/initdb"
152+
$createdb_path = "${bindir}/createdb"
153+
$psql_path = "${bindir}/psql"
154+
$pg_hba_conf_path = "${confdir}/pg_hba.conf"
155+
$postgresql_conf_path = "${confdir}/postgresql.conf"
95156
}

0 commit comments

Comments
 (0)