diff --git a/.vscode/settings.json b/.vscode/settings.json
index 5bf56fa..87311dd 100644
--- a/.vscode/settings.json
+++ b/.vscode/settings.json
@@ -47,6 +47,7 @@
"tablespaces",
"tidscan",
"timezonesets",
+ "usename",
"walsender",
"writethrough",
"xacts",
diff --git a/doc/_index.html b/doc/_index.html
index 29a3698..b5002f7 100644
--- a/doc/_index.html
+++ b/doc/_index.html
@@ -144,6 +144,11 @@
+
+ postgresql_cd::server::roles::role_df
+
+
+
diff --git a/doc/puppet_classes/postgresql_cd_3A_3Aparams.html b/doc/puppet_classes/postgresql_cd_3A_3Aparams.html
index 2479581..6913895 100644
--- a/doc/puppet_classes/postgresql_cd_3A_3Aparams.html
+++ b/doc/puppet_classes/postgresql_cd_3A_3Aparams.html
@@ -378,6 +378,24 @@
—
+
+
+
+
+
+ pl_manage_roles
+
+
+ (Boolean)
+
+
+ (defaults to: true)
+
+
+ —
+
@@ -393,7 +411,6 @@
-23
24
25
26
@@ -436,10 +453,12 @@
63
64
65
-66
+66
+67
+68
- # File 'manifests/params.pp', line 23
+ # File 'manifests/params.pp', line 24
class postgresql_cd::params (
@@ -464,6 +483,7 @@ class postgresql_cd::params (
String $pl_server_crt = 'server.crt',
String $pl_server_key = 'server.key',
String $pl_ca_crt = 'root.crt',
+ Boolean $pl_manage_roles = true,
) {
$fqdn = $facts['networking']['fqdn']
diff --git a/doc/puppet_defined_type_list.html b/doc/puppet_defined_type_list.html
index 027e4eb..b8f2071 100644
--- a/doc/puppet_defined_type_list.html
+++ b/doc/puppet_defined_type_list.html
@@ -47,6 +47,13 @@
+
+
+
+
+
diff --git a/doc/puppet_defined_types/postgresql_cd_3A_3Aserver_3A_3Aroles_3A_3Arole_df.html b/doc/puppet_defined_types/postgresql_cd_3A_3Aserver_3A_3Aroles_3A_3Arole_df.html
new file mode 100644
index 0000000..72cf6be
--- /dev/null
+++ b/doc/puppet_defined_types/postgresql_cd_3A_3Aserver_3A_3Aroles_3A_3Arole_df.html
@@ -0,0 +1,238 @@
+
+
+
+
+
+
+ Defined Type: postgresql_cd::server::roles::role_df
+
+ — Documentation by YARD 0.9.36
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ Defined Type: postgresql_cd::server::roles::role_df
+
+
+ - Defined in:
+ -
+ manifests/server/roles/role_df.pp
+
+
+
+
+ Summary
+ define manages databases
+
+ Overview
+
+
+
+
+
+
+
+
+
+
+
+12
+13
+14
+15
+16
+17
+18
+19
+20
+21
+22
+23
+24
+25
+26
+27
+28
+29
+30
+31
+32
+33
+ |
+
+ # File 'manifests/server/roles/role_df.pp', line 12
+
+define postgresql_cd::server::roles::role_df (
+
+ Optional[String] $pl_role_name = undef,
+ Optional[String] $pl_role_pw = undef,
+ String $pl_role_attributes = 'LOGIN',
+ String $pl_role_status = 'CREATE ROLE',
+
+) {
+ $pl_manage_roles = $postgresql_cd::params::pl_manage_roles
+
+ if $pl_manage_roles == true {
+ # create the role
+
+ exec { "role_${name}":
+ command => template('postgresql_cd/server/roles/role.sql.erb'),
+ user => 'postgres',
+ path => ['/usr/bin','/bin'],
+ cwd => '/tmp',
+ unless => template('postgresql_cd/server/roles/unless_sql.erb'),
+ }
+ }
+}
+ |
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/manifests/params.pp b/manifests/params.pp
index 5177ffc..724ede5 100644
--- a/manifests/params.pp
+++ b/manifests/params.pp
@@ -18,6 +18,7 @@
# @param [String] pl_server_crt the name of the server cert
# @param [String] pl_server_key the name of the server key
# @param [String] pl_ca_crt the name of the CA crt
+# @param [Boolean] pl_manage_roles Whether to manage roles
# @summary Class contains all parameters for the postgresql_cd module.
##############################################################################
class postgresql_cd::params (
@@ -43,6 +44,7 @@ class postgresql_cd::params (
String $pl_server_crt = 'server.crt',
String $pl_server_key = 'server.key',
String $pl_ca_crt = 'root.crt',
+ Boolean $pl_manage_roles = true,
) {
$fqdn = $facts['networking']['fqdn']
diff --git a/manifests/server/roles/role_df.pp b/manifests/server/roles/role_df.pp
new file mode 100644
index 0000000..9bca733
--- /dev/null
+++ b/manifests/server/roles/role_df.pp
@@ -0,0 +1,33 @@
+## postgresql_cd::server::roles::role_df
+# Module name: postgresql_cd
+# Author: Arne Teuke (arne_teuke@confdroid.com)
+
+# @summary define manages databases
+# @see https://www.postgresql.org/docs/9.6/static/managing-databases.html
+# @param [string] pl_role_name the name of the role to be created.
+# @param [string] pl_role_pw the password to be created
+# @param [string] pl_role_attributes attributes for the role to be created
+# @param [string] pl_role_status what to do with the role
+##############################################################################
+define postgresql_cd::server::roles::role_df (
+
+ Optional[String] $pl_role_name = undef,
+ Optional[String] $pl_role_pw = undef,
+ String $pl_role_attributes = 'LOGIN',
+ String $pl_role_status = 'CREATE ROLE',
+
+) {
+ $pl_manage_roles = $postgresql_cd::params::pl_manage_roles
+
+ if $pl_manage_roles == true {
+ # create the role
+
+ exec { "role_${name}":
+ command => template('postgresql_cd/server/roles/role.sql.erb'),
+ user => 'postgres',
+ path => ['/usr/bin','/bin'],
+ cwd => '/tmp',
+ unless => template('postgresql_cd/server/roles/unless_sql.erb'),
+ }
+ }
+}
diff --git a/templates/server/roles/role.sql.erb b/templates/server/roles/role.sql.erb
new file mode 100644
index 0000000..4667473
--- /dev/null
+++ b/templates/server/roles/role.sql.erb
@@ -0,0 +1 @@
+psql -U postgres -c "<%= @pl_role_status %> <%= @pl_role_name %> WITH <%= @pl_role_attributes %> PASSWORD '<%= @pl_role_pw %>'"
diff --git a/templates/server/roles/unless_sql.erb b/templates/server/roles/unless_sql.erb
new file mode 100644
index 0000000..e288881
--- /dev/null
+++ b/templates/server/roles/unless_sql.erb
@@ -0,0 +1 @@
+psql -U postgres -c "SELECT usename FROM pg_user WHERE usename='<%= @pl_role_name %>' " | grep -o 1
|