1 # Class: postgresql::params
3 # The postgresql configuration settings.
16 # This class allows you to use a newer version of postgres, rather than your
17 # system's default version.
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.
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.
30 class postgresql::params(
31 $version = $::postgres_default_version,
32 $manage_package_repo = false,
33 $package_source = undef,
36 $custom_datadir = undef,
37 $custom_confdir = undef,
38 $custom_bindir = undef,
39 $custom_client_package_name = undef,
40 $custom_server_package_name = undef,
41 $custom_contrib_package_name = undef,
42 $custom_devel_package_name = undef,
43 $custom_java_package_name = undef,
44 $custom_plperl_package_name = undef,
45 $custom_service_name = undef,
47 $custom_group = undef,
50 $user = pick($custom_user, 'postgres')
51 $group = pick($custom_group, 'postgres')
52 $ip_mask_deny_postgres_user = '0.0.0.0/0'
53 $ip_mask_allow_all_users = '127.0.0.1/32'
54 $listen_addresses = 'localhost'
57 $manage_pg_hba_conf = true
58 # TODO: figure out a way to make this not platform-specific
59 $manage_redhat_firewall = false
61 if ($manage_package_repo) {
64 $rh_pkg_source = pick($package_source, 'yum.postgresql.org')
67 'yum.postgresql.org': {
68 class { 'postgresql::package_source::yum_postgresql_org':
74 fail("Unsupported package source '${rh_pkg_source}' for ${::osfamily} OS family. Currently the only supported source is 'yum.postgresql.org'")
80 class { 'postgresql::package_source::apt_postgresql_org': }
84 fail("Unsupported osfamily for manage_package_repo: ${::osfamily} operatingsystem: ${::operatingsystem}, module ${module_name} currently only supports managing repos for osfamily RedHat and Debian")
90 # This is a bit hacky, but if the puppet nodes don't have pluginsync enabled,
91 # they will fail with a not-so-helpful error message. Here we are explicitly
92 # verifying that the custom fact exists (which implies that pluginsync is
93 # enabled and succeeded). If not, we fail with a hint that tells the user
94 # that pluginsync might not be enabled. Ideally this would be handled directly
96 if ($::postgres_default_version == undef) {
97 fail "No value for postgres_default_version facter fact; it's possible that you don't have pluginsync enabled."
100 case $::operatingsystem {
102 $service_provider = undef
106 # Amazon Linux's OS Family is 'Linux', operating system 'Amazon'.
109 $needs_initdb = pick($run_initdb, true)
110 $firewall_supported = true
111 $persist_firewall_command = '/sbin/iptables-save > /etc/sysconfig/iptables'
113 if $version == $::postgres_default_version {
114 $client_package_name = pick($custom_client_package_name, 'postgresql')
115 $server_package_name = pick($custom_server_package_name, 'postgresql-server')
116 $contrib_package_name = pick($custom_contrib_package_name,'postgresql-contrib')
117 $devel_package_name = pick($custom_devel_package_name, 'postgresql-devel')
118 $java_package_name = pick($custom_java_package_name, 'postgresql-jdbc')
119 $plperl_package_name = pick($custom_plperl_package_name, 'postgresql-plperl')
120 $service_name = pick($custom_service_name, 'postgresql')
121 $bindir = pick($custom_bindir, '/usr/bin')
122 $datadir = pick($custom_datadir, '/var/lib/pgsql/data')
123 $confdir = pick($custom_confdir, $datadir)
125 $version_parts = split($version, '[.]')
126 $package_version = "${version_parts[0]}${version_parts[1]}"
127 $client_package_name = pick($custom_client_package_name, "postgresql${package_version}")
128 $server_package_name = pick($custom_server_package_name, "postgresql${package_version}-server")
129 $contrib_package_name = pick($custom_contrib_package_name,"postgresql${package_version}-contrib")
130 $devel_package_name = pick($custom_devel_package_name, "postgresql${package_version}-devel")
131 $java_package_name = pick($custom_java_package_name, "postgresql${package_version}-jdbc")
132 $plperl_package_name = pick($custom_plperl_package_name, "postgresql${package_version}-plperl")
133 $service_name = pick($custom_service_name, "postgresql-${version}")
134 $bindir = pick($custom_bindir, "/usr/pgsql-${version}/bin")
135 $datadir = pick($custom_datadir, "/var/lib/pgsql/${version}/data")
136 $confdir = pick($custom_confdir, $datadir)
139 $service_status = undef
140 $python_package_name="python-psycopg2"
144 $firewall_supported = false
145 # TODO: not exactly sure yet what the right thing to do for Debian/Ubuntu is.
146 #$persist_firewall_command = '/sbin/iptables-save > /etc/iptables/rules.v4'
148 if $manage_package_repo == true {
149 $needs_initdb = pick($run_initdb, true)
150 $service_name = pick($custom_service_name, 'postgresql')
152 $needs_initdb = pick($run_initdb, false)
153 case $::operatingsystem {
155 $service_name = pick($custom_service_name, 'postgresql')
159 if($::lsbmajdistrelease == '10') {
160 $service_name = pick($custom_service_name, "postgresql-${version}")
162 $service_name = pick($custom_service_name, 'postgresql')
168 $client_package_name = pick($custom_client_package_name, "postgresql-client-${version}")
169 $server_package_name = pick($custom_server_package_name, "postgresql-${version}")
170 $contrib_package_name = pick($custom_contrib_package_name, "postgresql-contrib-${version}")
171 $devel_package_name = pick($custom_devel_package_name, 'libpq-dev')
172 $java_package_name = pick($custom_java_package_name, 'libpostgresql-jdbc-java')
173 $bindir = pick($custom_bindir, "/usr/lib/postgresql/${version}/bin")
174 $datadir = pick($custom_datadir, "/var/lib/postgresql/${version}/main")
175 $confdir = pick($custom_confdir, "/etc/postgresql/${version}/main")
176 $service_status = "/etc/init.d/${service_name} status | /bin/egrep -q 'Running clusters: .+|online'"
177 $python_package_name = "python-psycopg2"
178 $plperl_package_name = "postgresql-plperl-${version}"
183 $err_msg_prefix = "Module ${module_name} does not provide defaults for osfamily: ${::osfamily} operatingsystem: ${::operatingsystem}; please specify a value for ${module_name}::params::"
185 if ($run_initdb != undef) {
186 $needs_initdb = $run_initdb
188 fail("${err_msg_prefix}run_initdb")
191 $firewall_supported = false
193 if ($custom_service_name) {
194 $service_name = $custom_service_name
196 fail("${err_msg_prefix}custom_service_name")
199 if ($custom_client_package_name) {
200 $client_package_name = $custom_client_package_name
202 fail("${err_msg_prefix}custom_client_package_name")
205 if ($custom_server_package_name) {
206 $server_package_name = $custom_server_package_name
208 fail("${err_msg_prefix}custom_server_package_name")
212 $contrib_package_name = $custom_contrib_package_name
213 $devel_package_name = $custom_devel_package_name
214 $java_package_name = $custom_java_package_name
216 if ($custom_bindir) {
217 $bindir = $custom_bindir
219 fail("${err_msg_prefix}custom_bindir")
222 if ($custom_datadir) {
223 $datadir = $custom_datadir
225 fail("${err_msg_prefix}custom_datadir")
228 if ($custom_confdir) {
229 $confdir = $custom_confdir
231 fail("${err_msg_prefix}custom_confdir")
234 $service_status = undef
238 $initdb_path = "${bindir}/initdb"
239 $createdb_path = "${bindir}/createdb"
240 $psql_path = "${bindir}/psql"
241 $pg_hba_conf_path = "${confdir}/pg_hba.conf"
242 $postgresql_conf_path = "${confdir}/postgresql.conf"