role.pp 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142
  1. # puppet-postgresql
  2. # For all details and documentation:
  3. # http://github.com/inkling/puppet-postgresql
  4. #
  5. # Copyright 2012- Inkling Systems, Inc.
  6. #
  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
  10. #
  11. # http://www.apache.org/licenses/LICENSE-2.0
  12. #
  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.
  18. define postgresql::role(
  19. $password_hash,
  20. $createdb = false,
  21. $createrole = false,
  22. $db = 'postgres',
  23. $login = false,
  24. $superuser = false,
  25. $username = $title
  26. ) {
  27. include postgresql::params
  28. $login_sql = $login ? { true => 'LOGIN' , default => 'NOLOGIN' }
  29. $createrole_sql = $createrole ? { true => 'CREATEROLE', default => 'NOCREATEROLE' }
  30. $createdb_sql = $createdb ? { true => 'CREATEDB' , default => 'NOCREATEDB' }
  31. $superuser_sql = $superuser ? { true => 'SUPERUSER' , default => 'NOSUPERUSER' }
  32. # TODO: FIXME: Will not correct the superuser / createdb / createrole / login status of a role that already exists
  33. postgresql_psql {"CREATE ROLE ${username} ENCRYPTED PASSWORD '${password_hash}' ${login_sql} ${createrole_sql} ${createdb_sql} ${superuser_sql}":
  34. db => $db,
  35. psql_user => 'postgres',
  36. unless => "SELECT rolname FROM pg_roles WHERE rolname='${username}'",
  37. cwd => $postgresql::params::datadir,
  38. }
  39. }