Skip to content

Commit 34d9874

Browse files
committed
Added defined type to grant roles to roles
1 parent 5bf5f5f commit 34d9874

File tree

1 file changed

+30
-0
lines changed

1 file changed

+30
-0
lines changed

manifests/server/role_grant.pp

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
# Define for granting roles to users.
2+
define postgresql::server::role_grant (
3+
$role,
4+
$user,
5+
$admin_option = false
6+
) {
7+
8+
if $admin_option {
9+
$grant_cmd = "GRANT \"${role}\" TO \"${user}\" WITH ADMIN OPTION"
10+
} else {
11+
$grant_cmd = "GRANT \"${role}\" TO \"${user}\""
12+
}
13+
14+
postgresql_psql { $grant_cmd:
15+
db => $on_db,
16+
psql_user => $psql_user,
17+
psql_group => $group,
18+
psql_path => $psql_path,
19+
unless => "SELECT 1 WHERE pg_has_role('${user}', '${role}', 'USAGE')",
20+
require => Class['postgresql::server']
21+
}
22+
23+
if($role != undef and defined(Postgresql::Server::Role[$role])) {
24+
Postgresql::Server::Role[$role]->Postgresql_psql[$grant_cmd]
25+
}
26+
27+
if($db != undef and defined(Postgresql::Server::Role[$user])) {
28+
Postgresql::Server::Role[$user]->Postgresql_psql[$grant_cmd]
29+
}
30+
}

0 commit comments

Comments
 (0)