module-postgresql/manifests/params.pp

274 lines
15 KiB
ObjectPascal
Raw Normal View History

# PRIVATE CLASS: do not use directly
class postgresql::params inherits postgresql::globals {
2015-01-11 05:27:57 +01:00
$version = $postgresql::globals::globals_version
$postgis_version = $postgresql::globals::globals_postgis_version
$listen_addresses = 'localhost'
$port = 5432
2016-03-30 10:05:46 +02:00
$log_line_prefix = '%t '
$ip_mask_deny_postgres_user = '0.0.0.0/0'
$ip_mask_allow_all_users = '127.0.0.1/32'
$ipv4acls = []
$ipv6acls = []
2015-01-11 05:27:57 +01:00
$encoding = $postgresql::globals::encoding
$locale = $postgresql::globals::locale
Remove the ensure => absent uninstall code. This is likely to be a controversial change so I wanted to put some explanation of our reasoning into the commit message. This gets kind of complex so I'll start with the problem and then the reasoning. Problem: We rely heavily on the ability to uninstall and reinstall postgres throughout our testing code, testing features like "can I move from the distribution packages to the upstream packages through the module" and over time we've learnt that the uninstall code simply doesn't work a lot of the time. It leaves traces of postgres behind or fails to remove certain packages on Ubuntu, and generally causes bits to be left on your system that you didn't expect. When we then reinstall things fail because it's not a true clean slate, and this causes us enormous problems during test. We've spent weeks and months working on these tests and they simply don't hold up well across the full range of PE platforms. Reasoning: Due to all these problems we've decided to take a stance on uninstalling in general. We feel that in 2014 it's completely reasonable and normal to have a good provisioning pipeline combined with your configuration management and the "correct" way to uninstall a fully installed service like postgresql is to simply reprovision the server without it in the first place. As a general rule this is how I personally like to work and I think is a good practice. WAIT A MINUTE: We understand that there are environments and situations in which it's not easy to do that. What if you accidently deployed Postgres on 100,000 nodes? When this work is finished I'm going to take a look at building some example 'profiles' to be found under examples/ within this module that can uninstall postgres on popular platforms. These can be modified and used in your specific case to uninstall postgresql. They will be much more brute force and reliant on deleting entire directories and require you to do more work up front in specifying where things are installed but we think it'll prove to be a much cleaner mechanism for this kind of thing rather than trying to weave it into the main module logic itself.
2014-07-02 16:45:07 +02:00
$service_ensure = 'running'
$service_enable = true
$service_manage = true
$service_restart_on_change = true
$service_provider = $postgresql::globals::service_provider
$manage_pg_hba_conf = pick($manage_pg_hba_conf, true)
2014-07-30 22:55:20 +02:00
$manage_pg_ident_conf = pick($manage_pg_ident_conf, true)
$manage_recovery_conf = pick($manage_recovery_conf, false)
Remove the ensure => absent uninstall code. This is likely to be a controversial change so I wanted to put some explanation of our reasoning into the commit message. This gets kind of complex so I'll start with the problem and then the reasoning. Problem: We rely heavily on the ability to uninstall and reinstall postgres throughout our testing code, testing features like "can I move from the distribution packages to the upstream packages through the module" and over time we've learnt that the uninstall code simply doesn't work a lot of the time. It leaves traces of postgres behind or fails to remove certain packages on Ubuntu, and generally causes bits to be left on your system that you didn't expect. When we then reinstall things fail because it's not a true clean slate, and this causes us enormous problems during test. We've spent weeks and months working on these tests and they simply don't hold up well across the full range of PE platforms. Reasoning: Due to all these problems we've decided to take a stance on uninstalling in general. We feel that in 2014 it's completely reasonable and normal to have a good provisioning pipeline combined with your configuration management and the "correct" way to uninstall a fully installed service like postgresql is to simply reprovision the server without it in the first place. As a general rule this is how I personally like to work and I think is a good practice. WAIT A MINUTE: We understand that there are environments and situations in which it's not easy to do that. What if you accidently deployed Postgres on 100,000 nodes? When this work is finished I'm going to take a look at building some example 'profiles' to be found under examples/ within this module that can uninstall postgres on popular platforms. These can be modified and used in your specific case to uninstall postgresql. They will be much more brute force and reliant on deleting entire directories and require you to do more work up front in specifying where things are installed but we think it'll prove to be a much cleaner mechanism for this kind of thing rather than trying to weave it into the main module logic itself.
2014-07-02 16:45:07 +02:00
$package_ensure = 'present'
# Amazon Linux's OS Family is 'Linux', operating system 'Amazon'.
case $::osfamily {
'RedHat', 'Linux': {
$link_pg_config = true
$user = pick($user, 'postgres')
$group = pick($group, 'postgres')
$needs_initdb = pick($needs_initdb, true)
2014-04-08 16:40:49 +02:00
$version_parts = split($version, '[.]')
$package_version = "${version_parts[0]}${version_parts[1]}"
if $version == $postgresql::globals::default_version and $::operatingsystem != 'Amazon' {
$client_package_name = pick($client_package_name, 'postgresql')
$server_package_name = pick($server_package_name, 'postgresql-server')
$contrib_package_name = pick($contrib_package_name,'postgresql-contrib')
$devel_package_name = pick($devel_package_name, 'postgresql-devel')
$java_package_name = pick($java_package_name, 'postgresql-jdbc')
$docs_package_name = pick($docs_package_name, 'postgresql-docs')
$plperl_package_name = pick($plperl_package_name, 'postgresql-plperl')
$plpython_package_name = pick($plpython_package_name, 'postgresql-plpython')
$service_name = pick($service_name, 'postgresql')
$bindir = pick($bindir, '/usr/bin')
$datadir = $::operatingsystem ? {
'Amazon' => pick($datadir, "/var/lib/pgsql${package_version}/data"),
default => pick($datadir, '/var/lib/pgsql/data'),
}
$confdir = pick($confdir, $datadir)
} else {
$client_package_name = pick($client_package_name, "postgresql${package_version}")
$server_package_name = pick($server_package_name, "postgresql${package_version}-server")
$contrib_package_name = pick($contrib_package_name,"postgresql${package_version}-contrib")
$devel_package_name = pick($devel_package_name, "postgresql${package_version}-devel")
$java_package_name = pick($java_package_name, "postgresql${package_version}-jdbc")
$docs_package_name = pick($docs_package_name, "postgresql${package_version}-docs")
$plperl_package_name = pick($plperl_package_name, "postgresql${package_version}-plperl")
$plpython_package_name = pick($plpython_package_name, "postgresql${package_version}-plpython")
$service_name = $::operatingsystem ? {
postgres server init script naming on amazon linux ami On current amazon linux ami (details below), and open puppet (details below), the postgres module (installed as part of puppetlabs/puppetdb) currently, tries to start postgressql server with /etc/init.d/postgresql9.4 , while the init script doesn't have the dot in the version number, so it needs to use /etc/init.d/postgresql94 From what I see in all available postgresql server rpms, currently on amazon linux ami, seems all the init scripts of postgresql doesn't have a dot in the suffix version number. Supporting info: [root@puppet ~]# yum list postgres* | grep 'server\.'; postgresql94-server.x86_64 9.4.5-1.63.amzn1 @amzn-updates postgresql8-server.x86_64 8.4.20-4.51.amzn1 amzn-updates postgresql92-server.x86_64 9.2.14-1.56.amzn1 amzn-updates postgresql93-server.x86_64 9.3.10-1.60.amzn1 amzn-updates for i in postgresql8-server.x86_64 postgresql92-server.x86_64 postgresql93-server.x86_64 postgresql94-server.x86_64; do echo $i; repoquery -l $i | grep init.d; done postgresql8-server.x86_64 /etc/rc.d/init.d/postgresql postgresql92-server.x86_64 /etc/rc.d/init.d/postgresql92 postgresql93-server.x86_64 /etc/rc.d/init.d/postgresql93 postgresql94-server.x86_64 [root@puppet ~]# puppet --version 4.3.2 [root@puppet ~]# rpm -qa | grep puppet | grep server puppetserver-2.2.1-1.el6.noarch [root@puppet ~]# [root@puppet ~]# cat /etc/os-release NAME="Amazon Linux AMI" VERSION="2015.09" ID="amzn" ID_LIKE="rhel fedora" VERSION_ID="2015.09" PRETTY_NAME="Amazon Linux AMI 2015.09" ANSI_COLOR="0;33" CPE_NAME="cpe:/o:amazon:linux:2015.09:ga" HOME_URL="http://aws.amazon.com/amazon-linux-ami/" [root@puppet ~]# [root@puppet ~]# cat /etc/system-release Amazon Linux AMI release 2015.09
2016-02-12 02:27:02 +01:00
'Amazon' => pick($service_name, "postgresql${version_parts[0]}${version_parts[1]}"),
default => pick($service_name, "postgresql-${version}"),
}
$bindir = $::operatingsystem ? {
'Amazon' => pick($bindir, '/usr/bin'),
default => pick($bindir, "/usr/pgsql-${version}/bin"),
}
$datadir = $::operatingsystem ? {
'Amazon' => pick($datadir, "/var/lib/pgsql${package_version}/data"),
default => pick($datadir, "/var/lib/pgsql/${version}/data"),
}
$confdir = pick($confdir, $datadir)
}
$psql_path = pick($psql_path, "${bindir}/psql")
$service_status = $service_status
$service_reload = "service ${service_name} reload"
$perl_package_name = pick($perl_package_name, 'perl-DBD-Pg')
$python_package_name = pick($python_package_name, 'python-psycopg2')
if $postgresql::globals::postgis_package_name {
$postgis_package_name = $postgresql::globals::postgis_package_name
} elsif $::operatingsystemrelease =~ /^5\./ {
$postgis_package_name = 'postgis'
} elsif $postgis_version and versioncmp($postgis_version, '2') < 0 {
$postgis_package_name = "postgis${package_version}"
} else {
$postgis_package_name = "postgis2_${package_version}"
}
}
2013-09-21 16:48:03 +02:00
'Archlinux': {
$link_pg_config = true
2013-09-21 16:48:03 +02:00
$needs_initdb = pick($needs_initdb, true)
$user = pick($user, 'postgres')
$group = pick($group, 'postgres')
2013-09-21 16:48:03 +02:00
# Archlinux doesn't have a client-package but has a libs package which
# pulls in postgresql server
$client_package_name = pick($client_package_name, 'postgresql')
$server_package_name = pick($server_package_name, 'postgresql-libs')
$java_package_name = pick($java_package_name, 'postgresql-jdbc')
2013-09-21 16:48:03 +02:00
# Archlinux doesn't have develop packages
$devel_package_name = pick($devel_package_name, 'postgresql-devel')
2013-09-21 16:48:03 +02:00
# Archlinux does have postgresql-contrib but it isn't maintained
$contrib_package_name = pick($contrib_package_name,'undef')
2013-09-21 16:48:03 +02:00
# Archlinux postgresql package provides plperl
$plperl_package_name = pick($plperl_package_name, 'undef')
$plpython_package_name = pick($plpython_package_name, 'undef')
$service_name = pick($service_name, 'postgresql')
$bindir = pick($bindir, '/usr/bin')
$datadir = pick($datadir, '/var/lib/postgres/data')
$confdir = pick($confdir, $datadir)
$psql_path = pick($psql_path, "${bindir}/psql")
2013-09-21 16:48:03 +02:00
$service_status = $service_status
$service_reload = "systemctl reload ${service_name}"
$python_package_name = pick($python_package_name, 'python-psycopg2')
# Archlinux does not have a perl::DBD::Pg package
$perl_package_name = pick($perl_package_name, 'undef')
2013-09-21 16:48:03 +02:00
}
'Debian': {
$link_pg_config = false
$user = pick($user, 'postgres')
$group = pick($group, 'postgres')
2015-01-11 05:27:57 +01:00
if $postgresql::globals::manage_package_repo == true {
$needs_initdb = pick($needs_initdb, true)
$service_name = pick($service_name, 'postgresql')
} else {
$needs_initdb = pick($needs_initdb, false)
$service_name = $::operatingsystem ? {
'Debian' => pick($service_name, 'postgresql'),
'Ubuntu' => $::lsbmajdistrelease ? {
/^10/ => pick($service_name, "postgresql-${version}"),
default => pick($service_name, 'postgresql'),
},
default => undef
}
}
$client_package_name = pick($client_package_name, "postgresql-client-${version}")
$server_package_name = pick($server_package_name, "postgresql-${version}")
$contrib_package_name = pick($contrib_package_name, "postgresql-contrib-${version}")
if $postgis_version and versioncmp($postgis_version, '2') < 0 {
2015-02-25 13:50:32 +01:00
$postgis_package_name = pick($postgis_package_name, "postgresql-${version}-postgis")
} else {
$postgis_package_name = pick($postgis_package_name, "postgresql-${version}-postgis-${postgis_version}")
}
$devel_package_name = pick($devel_package_name, 'libpq-dev')
$java_package_name = pick($java_package_name, 'libpostgresql-jdbc-java')
$perl_package_name = pick($perl_package_name, 'libdbd-pg-perl')
$plperl_package_name = pick($plperl_package_name, "postgresql-plperl-${version}")
$plpython_package_name = pick($plpython_package_name, "postgresql-plpython-${version}")
$python_package_name = pick($python_package_name, 'python-psycopg2')
$bindir = pick($bindir, "/usr/lib/postgresql/${version}/bin")
$datadir = pick($datadir, "/var/lib/postgresql/${version}/main")
$confdir = pick($confdir, "/etc/postgresql/${version}/main")
if $::operatingsystem == 'Debian' and versioncmp($::operatingsystemrelease, '8.0') >= 0 {
# Jessie uses systemd
$service_status = pick($service_status, "/usr/sbin/service ${service_name}@*-main status")
2016-02-20 19:55:19 +01:00
} elsif $::operatingsystem == 'Ubuntu' and versioncmp($::operatingsystemrelease, '15.04') >= 0 {
# Ubuntu releases since vivid use systemd
$service_status = pick($service_status, "/usr/sbin/service ${service_name} status")
} else {
$service_status = pick($service_status, "/etc/init.d/${service_name} status | /bin/egrep -q 'Running clusters: .+|online'")
}
$service_reload = "service ${service_name} reload"
$psql_path = pick($psql_path, '/usr/bin/psql')
}
'FreeBSD': {
$link_pg_config = true
$user = pick($user, 'pgsql')
$group = pick($group, 'pgsql')
$client_package_name = pick($client_package_name, "databases/postgresql${version}-client")
$server_package_name = pick($server_package_name, "databases/postgresql${version}-server")
$contrib_package_name = pick($contrib_package_name, "databases/postgresql${version}-contrib")
$devel_package_name = pick($devel_package_name, 'databases/postgresql-libpqxx3')
$java_package_name = pick($java_package_name, 'databases/postgresql-jdbc')
$perl_package_name = pick($plperl_package_name, 'databases/p5-DBD-Pg')
$plperl_package_name = pick($plperl_package_name, "databases/postgresql${version}-plperl")
$python_package_name = pick($python_package_name, 'databases/py-psycopg2')
$service_name = pick($service_name, 'postgresql')
$bindir = pick($bindir, '/usr/local/bin')
$datadir = pick($datadir, '/usr/local/pgsql/data')
$confdir = pick($confdir, $datadir)
$service_status = pick($service_status, "/usr/local/etc/rc.d/${service_name} onestatus")
$service_reload = "service ${service_name} reload"
$psql_path = pick($psql_path, "${bindir}/psql")
$needs_initdb = pick($needs_initdb, true)
}
'OpenBSD': {
$user = pick($user, '_postgresql')
$group = pick($group, '_postgresql')
$client_package_name = pick($client_package_name, 'postgresql-client')
$server_package_name = pick($server_package_name, 'postgresql-server')
$contrib_package_name = pick($contrib_package_name, 'postgresql-contrib')
$devel_package_name = pick($devel_package_name, 'postgresql-client')
$java_package_name = pick($java_package_name, 'postgresql-jdbc')
$perl_package_name = pick($perl_package_name, 'databases/p5-DBD-Pg')
$plperl_package_name = undef
$python_package_name = pick($python_package_name, 'py-psycopg2')
$service_name = pick($service_name, 'postgresql')
$bindir = pick($bindir, '/usr/local/bin')
$datadir = pick($datadir, '/var/postgresql/data')
$confdir = pick($confdir, $datadir)
$service_status = pick($service_status, "/etc/rc.d/${service_name} check")
$service_reload = "/etc/rc.d/${service_name} reload"
$psql_path = pick($psql_path, "${bindir}/psql")
$needs_initdb = pick($needs_initdb, true)
}
'Suse': {
$link_pg_config = true
$user = pick($user, 'postgres')
$group = pick($group, 'postgres')
$client_package_name = pick($client_package_name, "postgresql${version}")
$server_package_name = pick($server_package_name, "postgresql${version}-server")
$contrib_package_name = pick($contrib_package_name, "postgresql${version}-contrib")
$devel_package_name = pick($devel_package_name, "postgresql${version}-devel")
$java_package_name = pick($java_package_name, "postgresql${version}-jdbc")
$perl_package_name = pick($plperl_package_name, 'perl-DBD-Pg')
$plperl_package_name = pick($plperl_package_name, "postgresql${version}-plperl")
$python_package_name = pick($python_package_name, 'python-psycopg2')
$service_name = pick($service_name, 'postgresql')
$bindir = pick($bindir, "/usr/lib/postgresql${version}/bin")
$datadir = pick($datadir, '/var/lib/pgsql/data')
2014-08-21 19:22:21 +02:00
$confdir = pick($confdir, $datadir)
$service_status = pick($service_status, "/etc/init.d/${service_name} status")
$service_reload = "/etc/init.d/${service_name} reload"
$psql_path = pick($psql_path, "${bindir}/psql")
$needs_initdb = pick($needs_initdb, true)
}
default: {
$link_pg_config = true
$psql_path = pick($psql_path, "${bindir}/psql")
# Since we can't determine defaults on our own, we rely on users setting
# parameters with the postgresql::globals class. Here we are checking
# that the mandatory minimum is set for the module to operate.
$err_prefix = "Module ${module_name} does not provide defaults for osfamily: ${::osfamily} operatingsystem: ${::operatingsystem}; please specify a value for ${module_name}::globals::"
if ($needs_initdb == undef) { fail("${err_prefix}needs_initdb") }
if ($service_name == undef) { fail("${err_prefix}service_name") }
if ($client_package_name == undef) { fail("${err_prefix}client_package_name") }
if ($server_package_name == undef) { fail("${err_prefix}server_package_name") }
if ($bindir == undef) { fail("${err_prefix}bindir") }
if ($datadir == undef) { fail("${err_prefix}datadir") }
if ($confdir == undef) { fail("${err_prefix}confdir") }
}
}
$validcon_script_path = pick($validcon_script_path, '/usr/local/bin/validate_postgresql_connection.sh')
$initdb_path = pick($initdb_path, "${bindir}/initdb")
$pg_hba_conf_path = pick($pg_hba_conf_path, "${confdir}/pg_hba.conf")
$pg_hba_conf_defaults = pick($pg_hba_conf_defaults, true)
$pg_ident_conf_path = pick($pg_ident_conf_path, "${confdir}/pg_ident.conf")
$postgresql_conf_path = pick($postgresql_conf_path, "${confdir}/postgresql.conf")
$recovery_conf_path = pick($recovery_conf_path, "${datadir}/recovery.conf")
$default_database = pick($default_database, 'postgres')
}