salsa: more mail setup
[mirror/dsa-puppet.git] / 3rdparty / modules / postgresql / manifests / params.pp
1 # Class: postgresql::params
2 #
3 #   The postgresql configuration settings.
4 #
5 # Parameters:
6 #
7 # Actions:
8 #
9 # Requires:
10 #
11 # Sample Usage:
12 #
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   $locale                      = undef,
35   $charset                     = 'UTF8',
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,
46   $custom_user                 = undef,
47   $custom_group                = undef,
48   $run_initdb                  = undef
49 ) {
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'
55   $ipv4acls                     = []
56   $ipv6acls                     = []
57   $manage_pg_hba_conf           = true
58   # TODO: figure out a way to make this not platform-specific
59   $manage_redhat_firewall       = false
60
61   if ($manage_package_repo) {
62     case $::osfamily {
63       'RedHat': {
64         $rh_pkg_source = pick($package_source, 'yum.postgresql.org')
65
66         case $rh_pkg_source {
67           'yum.postgresql.org': {
68             class { 'postgresql::package_source::yum_postgresql_org':
69               version => $version
70             }
71           }
72
73           default: {
74             fail("Unsupported package source '${rh_pkg_source}' for ${::osfamily} OS family. Currently the only supported source is 'yum.postgresql.org'")
75           }
76         }
77       }
78
79       'Debian': {
80         class { 'postgresql::package_source::apt_postgresql_org': }
81       }
82
83       default: {
84         fail("Unsupported osfamily for manage_package_repo: ${::osfamily} operatingsystem: ${::operatingsystem}, module ${module_name} currently only supports managing repos for osfamily RedHat and Debian")
85       }
86     }
87   }
88
89
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
95   # in puppet.
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."
98   }
99
100   case $::operatingsystem {
101     default: {
102       $service_provider = undef
103     }
104   }
105
106   # Amazon Linux's OS Family is 'Linux', operating system 'Amazon'.
107   case $::osfamily {
108     'RedHat', 'Linux': {
109       $needs_initdb             = pick($run_initdb, true)
110       $firewall_supported       = true
111       $persist_firewall_command = '/sbin/iptables-save > /etc/sysconfig/iptables'
112
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)
124       } else {
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)
137       }
138
139       $service_status = undef
140       $python_package_name="python-psycopg2"
141     }
142
143     'Debian': {
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'
147
148       if $manage_package_repo == true {
149         $needs_initdb             = pick($run_initdb, true)
150         $service_name = pick($custom_service_name, 'postgresql')
151       } else {
152         $needs_initdb             = pick($run_initdb, false)
153         case $::operatingsystem {
154           'Debian': {
155             $service_name = pick($custom_service_name, 'postgresql')
156           }
157           'Ubuntu': {
158             # thanks, ubuntu
159             if($::lsbmajdistrelease == '10') {
160               $service_name = pick($custom_service_name, "postgresql-${version}")
161             } else {
162               $service_name = pick($custom_service_name, 'postgresql')
163             }
164           }
165         }
166       }
167
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}"
179     }
180
181     default: {
182
183       $err_msg_prefix = "Module ${module_name} does not provide defaults for osfamily: ${::osfamily} operatingsystem: ${::operatingsystem}; please specify a value for ${module_name}::params::"
184
185       if ($run_initdb != undef) {
186         $needs_initdb = $run_initdb
187       } else {
188         fail("${err_msg_prefix}run_initdb")
189       }
190
191       $firewall_supported = false
192
193       if ($custom_service_name) {
194         $service_name = $custom_service_name
195       } else {
196         fail("${err_msg_prefix}custom_service_name")
197       }
198
199       if ($custom_client_package_name) {
200         $client_package_name = $custom_client_package_name
201       } else {
202         fail("${err_msg_prefix}custom_client_package_name")
203       }
204
205       if ($custom_server_package_name) {
206         $server_package_name = $custom_server_package_name
207       } else {
208         fail("${err_msg_prefix}custom_server_package_name")
209       }
210
211
212       $contrib_package_name = $custom_contrib_package_name
213       $devel_package_name = $custom_devel_package_name
214       $java_package_name = $custom_java_package_name
215
216       if ($custom_bindir) {
217         $bindir = $custom_bindir
218       } else {
219         fail("${err_msg_prefix}custom_bindir")
220       }
221
222       if ($custom_datadir) {
223         $datadir = $custom_datadir
224       } else {
225         fail("${err_msg_prefix}custom_datadir")
226       }
227
228       if ($custom_confdir) {
229         $confdir = $custom_confdir
230       } else {
231         fail("${err_msg_prefix}custom_confdir")
232       }
233
234       $service_status = undef
235     }
236   }
237
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"
243
244 }