2 # For all details and documentation:
3 # http://github.com/inkling/puppet-postgresql
5 # Copyright 2012- Inkling Systems, Inc.
7 # Licensed under the Apache License, Version 2.0 (the "License");
8 # you may not use this file except in compliance with the License.
9 # You may obtain a copy of the License at
11 # http://www.apache.org/licenses/LICENSE-2.0
13 # Unless required by applicable law or agreed to in writing, software
14 # distributed under the License is distributed on an "AS IS" BASIS,
15 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16 # See the License for the specific language governing permissions and
17 # limitations under the License.
19 define postgresql::role(
20 $password_hash = false,
27 $connection_limit = '-1',
30 include postgresql::params
32 $login_sql = $login ? { true => 'LOGIN' , default => 'NOLOGIN' }
33 $createrole_sql = $createrole ? { true => 'CREATEROLE' , default => 'NOCREATEROLE' }
34 $createdb_sql = $createdb ? { true => 'CREATEDB' , default => 'NOCREATEDB' }
35 $superuser_sql = $superuser ? { true => 'SUPERUSER' , default => 'NOSUPERUSER' }
36 $replication_sql = $replication ? { true => 'REPLICATION' , default => '' }
37 if ($password_hash != false) {
38 $password_sql = "ENCRYPTED PASSWORD '${password_hash}'"
45 psql_user => $postgresql::params::user,
46 psql_group => $postgresql::params::group,
47 psql_path => $postgresql::params::psql_path,
48 require => Postgresql_psql["CREATE ROLE \"${username}\" ${password_sql} ${login_sql} ${createrole_sql} ${createdb_sql} ${superuser_sql} ${replication_sql} CONNECTION LIMIT ${connection_limit}"],
51 postgresql_psql {"CREATE ROLE \"${username}\" ${password_sql} ${login_sql} ${createrole_sql} ${createdb_sql} ${superuser_sql} ${replication_sql} CONNECTION LIMIT ${connection_limit}":
52 unless => "SELECT rolname FROM pg_roles WHERE rolname='${username}'",
56 postgresql_psql {"ALTER ROLE \"${username}\" ${superuser_sql}":
57 unless => "SELECT rolname FROM pg_roles WHERE rolname='${username}' and rolsuper=${superuser}",
60 postgresql_psql {"ALTER ROLE \"${username}\" ${createdb_sql}":
61 unless => "SELECT rolname FROM pg_roles WHERE rolname='${username}' and rolcreatedb=${createdb}",
64 postgresql_psql {"ALTER ROLE \"${username}\" ${createrole_sql}":
65 unless => "SELECT rolname FROM pg_roles WHERE rolname='${username}' and rolcreaterole=${createrole}",
68 postgresql_psql {"ALTER ROLE \"${username}\" ${login_sql}":
69 unless => "SELECT rolname FROM pg_roles WHERE rolname='${username}' and rolcanlogin=${login}",
72 if(versioncmp($postgresql::params::version, '9.1') >= 0) {
73 postgresql_psql {"ALTER ROLE \"${username}\" ${replication_sql}":
74 unless => "SELECT rolname FROM pg_roles WHERE rolname='${username}' and rolreplication=${replication}",
78 postgresql_psql {"ALTER ROLE \"${username}\" CONNECTION LIMIT ${connection_limit}":
79 unless => "SELECT rolname FROM pg_roles WHERE rolname='${username}' and rolconnlimit=${connection_limit}",
83 postgresql_psql {"ALTER ROLE \"${username}\" ${password_sql}":
84 unless => "SELECT usename FROM pg_shadow WHERE usename='${username}' and passwd='${password_hash}'",