X-Git-Url: https://git.adam-barratt.org.uk/?a=blobdiff_plain;ds=sidebyside;f=3rdparty%2Fmodules%2Fpostgresql%2Fmanifests%2Fserver%2Ftablespace.pp;fp=3rdparty%2Fmodules%2Fpostgresql%2Fmanifests%2Fserver%2Ftablespace.pp;h=cf0b65dc0b8dc0e03333daa1e848da285882b5ce;hb=a69999e580f8b3abd12446c2d6ad59e517651813;hp=0000000000000000000000000000000000000000;hpb=e7b6b352165009c385c52fcfe5a1055690dbfa4b;p=mirror%2Fdsa-puppet.git diff --git a/3rdparty/modules/postgresql/manifests/server/tablespace.pp b/3rdparty/modules/postgresql/manifests/server/tablespace.pp new file mode 100644 index 000000000..cf0b65dc0 --- /dev/null +++ b/3rdparty/modules/postgresql/manifests/server/tablespace.pp @@ -0,0 +1,56 @@ +# This module creates tablespace. See README.md for more details. +define postgresql::server::tablespace( + $location, + $owner = undef, + $spcname = $title, + $connect_settings = $postgresql::server::default_connect_settings, +) { + $user = $postgresql::server::user + $group = $postgresql::server::group + $psql_path = $postgresql::server::psql_path + $module_workdir = $postgresql::server::module_workdir + + # If the connection settings do not contain a port, then use the local server port + if $connect_settings != undef and has_key( $connect_settings, 'PGPORT') { + $port = undef + } else { + $port = $postgresql::server::port + } + + Postgresql_psql { + psql_user => $user, + psql_group => $group, + psql_path => $psql_path, + port => $port, + connect_settings => $connect_settings, + cwd => $module_workdir, + } + + file { $location: + ensure => directory, + owner => $user, + group => $group, + mode => '0700', + seluser => 'system_u', + selrole => 'object_r', + seltype => 'postgresql_db_t', + require => Class['postgresql::server'], + } + + postgresql_psql { "CREATE TABLESPACE \"${spcname}\"": + command => "CREATE TABLESPACE \"${spcname}\" LOCATION '${location}'", + unless => "SELECT 1 FROM pg_tablespace WHERE spcname = '${spcname}'", + require => [Class['postgresql::server'], File[$location]], + } + + if $owner { + postgresql_psql { "ALTER TABLESPACE \"${spcname}\" OWNER TO \"${owner}\"": + unless => "SELECT 1 FROM pg_tablespace JOIN pg_roles rol ON spcowner = rol.oid WHERE spcname = '${spcname}' AND rolname = '${owner}'", + require => Postgresql_psql["CREATE TABLESPACE \"${spcname}\""], + } + + if defined(Postgresql::Server::Role[$owner]) { + Postgresql::Server::Role[$owner]->Postgresql_psql["ALTER TABLESPACE \"${spcname}\" OWNER TO \"${owner}\""] + } + } +}