2013-08-27 22:43:47 +02:00
|
|
|
# Define for conveniently creating a role, database and assigning the correct
|
|
|
|
# permissions. See README.md for more details.
|
|
|
|
define postgresql::server::db (
|
|
|
|
$user,
|
|
|
|
$password,
|
|
|
|
$encoding = $postgresql::server::encoding,
|
|
|
|
$locale = $postgresql::server::locale,
|
|
|
|
$grant = 'ALL',
|
|
|
|
$tablespace = undef,
|
2013-10-10 17:28:01 +02:00
|
|
|
$istemplate = false,
|
|
|
|
$owner = undef
|
2013-08-27 22:43:47 +02:00
|
|
|
) {
|
|
|
|
postgresql::server::database { $name:
|
|
|
|
encoding => $encoding,
|
|
|
|
tablespace => $tablespace,
|
|
|
|
locale => $locale,
|
|
|
|
istemplate => $istemplate,
|
2013-10-10 17:28:01 +02:00
|
|
|
owner => $owner,
|
2013-08-27 22:43:47 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
if ! defined(Postgresql::Server::Role[$user]) {
|
|
|
|
postgresql::server::role { $user:
|
2013-09-03 20:46:07 +02:00
|
|
|
password_hash => $password,
|
2013-08-27 22:43:47 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
postgresql::server::database_grant { "GRANT ${user} - ${grant} - ${name}":
|
2013-09-03 20:46:07 +02:00
|
|
|
privilege => $grant,
|
|
|
|
db => $name,
|
|
|
|
role => $user,
|
2013-08-27 22:43:47 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
if($tablespace != undef and defined(Postgresql::Server::Tablespace[$tablespace])) {
|
|
|
|
Postgresql::Server::Tablespace[$tablespace]->Postgresql::Server::Database[$name]
|
|
|
|
}
|
|
|
|
}
|