mirror of
https://github.com/Icinga/icingaweb2.git
synced 2025-09-26 11:19:14 +02:00
27 lines
983 B
Puppet
27 lines
983 B
Puppet
define pgsql::database::create ($username, $password) {
|
|
include pgsql
|
|
|
|
exec { "create-pgsql-${name}-db":
|
|
unless => "sudo -u postgres psql -tAc \"SELECT 1 FROM pg_roles WHERE rolname='${username}'\" | grep -q 1",
|
|
command => "sudo -u postgres psql -c \"CREATE ROLE ${username} WITH LOGIN PASSWORD '${password}';\" && \
|
|
sudo -u postgres createdb -O ${username} -E UTF8 -T template0 ${name} && \
|
|
sudo -u postgres createlang plpgsql ${name}",
|
|
require => Service['postgresql']
|
|
}
|
|
}
|
|
|
|
define pgsql::database::populate ($username, $password, $schemafile, $requirement) {
|
|
include pgsql
|
|
|
|
pgsql::database::create { $name:
|
|
username => $username,
|
|
password => $password,
|
|
}
|
|
|
|
exec { "populate-${name}-pgsql-db":
|
|
unless => "psql -U ${username} -d ${name} -c \"SELECT * FROM icinga_dbversion;\" &> /dev/null",
|
|
command => "sudo -u postgres psql -U ${username} -d ${name} < ${schemafile}",
|
|
require => [ $requirement, Exec["create-pgsql-${name}-db"] ]
|
|
}
|
|
}
|