module-postgresql/manifests/server/extension.pp
François Conil c1f4530634 Fixes MODULES_2059 - adds extension argument
This adds the ability to define the extension name separately from the
"title" of the resource, which allows you to add the extension to more
than one database.

As per the original ticket, extensions in postgresql can be defined on
a per database basis. By using the same name for both the extension and
the instance of postgresql::server::extension, you're getting duplicates
errors if you try to assign an extension to more than one database
2015-09-09 14:26:41 +10:00

61 lines
1.7 KiB
Puppet

# Activate an extension on a postgresql database
define postgresql::server::extension (
$database,
$extension = $name,
$ensure = 'present',
$package_name = undef,
$package_ensure = undef,
$connect_settings = $postgresql::server::default_connect_settings,
) {
$user = $postgresql::server::user
$group = $postgresql::server::group
$psql_path = $postgresql::server::psql_path
case $ensure {
'present': {
$command = "CREATE EXTENSION \"${extension}\""
$unless_comp = '='
$package_require = undef
$package_before = Postgresql_psql["Add ${extension} extension to ${database}"]
}
'absent': {
$command = "DROP EXTENSION \"${extension}\""
$unless_comp = '!='
$package_require = Postgresql_psql["Add ${extension} extension to ${database}"]
$package_before = undef
}
default: {
fail("Unknown value for ensure '${ensure}'.")
}
}
postgresql_psql {"Add ${extension} extension to ${database}":
psql_user => $user,
psql_group => $group,
psql_path => $psql_path,
connect_settings => $connect_settings,
db => $database,
command => $command,
unless => "SELECT t.count FROM (SELECT count(extname) FROM pg_extension WHERE extname = '${extension}') as t WHERE t.count ${unless_comp} 1",
require => Postgresql::Server::Database[$database],
}
if $package_name {
$_package_ensure = $package_ensure ? {
undef => $ensure,
default => $package_ensure,
}
ensure_packages($package_name, {
ensure => $_package_ensure,
tag => 'postgresql',
require => $package_require,
before => $package_before,
})
}
}