add db management - https://gitlab.confdroid.com/internal/confdroid_management/-/issues/239
This commit is contained in:
@@ -19,6 +19,7 @@
|
||||
# @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
|
||||
# @param [Boolean] pl_manage_databases Whether to manage databases
|
||||
# @summary Class contains all parameters for the postgresql_cd module.
|
||||
##############################################################################
|
||||
class postgresql_cd::params (
|
||||
@@ -45,6 +46,7 @@ class postgresql_cd::params (
|
||||
String $pl_server_key = 'server.key',
|
||||
String $pl_ca_crt = 'root.crt',
|
||||
Boolean $pl_manage_roles = true,
|
||||
Boolean $pl_manage_databases = true,
|
||||
|
||||
) {
|
||||
$fqdn = $facts['networking']['fqdn']
|
||||
|
||||
47
manifests/server/databases/db_df.pp
Normal file
47
manifests/server/databases/db_df.pp
Normal file
@@ -0,0 +1,47 @@
|
||||
## postgresql_cd::server::databases::db_df
|
||||
# Module name: postgresql_cd
|
||||
# Author: Arne Teuke (arne_teuke@confdroid.com.com)
|
||||
# @summary define manages databases
|
||||
# @see https://www.postgresql.org/docs/9.6/static/managing-databases.html
|
||||
# @param [String] pl_db_name the name of the database to be created.
|
||||
# @param [String] pl_owner_name the name of the owner for the database
|
||||
# (optional), if none specified, the postgresql defaults will apply.
|
||||
# @param [String] pl_db_action whether to create or drop the database.
|
||||
# 'CREATE DATABASE' creates it, 'DROP DATABASE' drops it.
|
||||
# @param [String] pl_db_extension
|
||||
##############################################################################
|
||||
define postgresql_cd::server::databases::db_df (
|
||||
|
||||
Optional[String] $pl_db_name = undef,
|
||||
Optional[String] $pl_owner_name = undef,
|
||||
Optional[String] $pl_db_action = undef,
|
||||
String $pl_db_extension = 'pg_trgm',
|
||||
) {
|
||||
$pl_manage_databases = $postgresql_cd::params::pl_manage_databases
|
||||
|
||||
if $pl_manage_databases == true {
|
||||
# create databases
|
||||
|
||||
if $pl_db_action == 'CREATE DATABASE' {
|
||||
exec { "create_database_${name}":
|
||||
command => template('postgresql_cd/server/databases/db_create_sql.erb'),
|
||||
user => 'postgres',
|
||||
path => ['/usr/bin','/bin'],
|
||||
cwd => '/tmp',
|
||||
unless => template('postgresql_cd/server/databases/unless_db_sql.erb'),
|
||||
}
|
||||
}
|
||||
|
||||
# Drop databases
|
||||
|
||||
if $pl_db_action == 'DROP DATABASE' {
|
||||
exec { "drop_database_${name}":
|
||||
command => template('postgresql_cd/server/databases/db_drop_sql.erb'),
|
||||
user => 'postgres',
|
||||
path => ['/usr/bin','/bin'],
|
||||
cwd => '/tmp',
|
||||
onlyif => template('postgresql_cd/server/databases/unless_drop_sql.erb'),
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user