Outsource Icinga database creation and population into pgsql::database

refs #6842
This commit is contained in:
Alexander Klimov 2014-08-05 14:42:01 +02:00
parent fe11ca4744
commit e42f400f38
2 changed files with 22 additions and 12 deletions

View File

@ -26,12 +26,11 @@ mysql::database { 'icinga2':
requirement => Package['icinga2-ido-mysql'],
}
exec{ 'create-pgsql-icinga-db':
unless => 'sudo -u postgres psql -tAc "SELECT 1 FROM pg_roles WHERE rolname=\'icinga\'" | grep -q 1',
command => 'sudo -u postgres psql -c "CREATE ROLE icinga WITH LOGIN PASSWORD \'icingaweb\';" && \
sudo -u postgres createdb -O icinga -E UTF8 -T template0 icinga && \
sudo -u postgres createlang plpgsql icinga',
require => Service['postgresql']
pgsql::database { 'icinga':
username => 'icinga',
password => 'icingaweb',
schemafile => "/usr/local/src/icinga-pgsql/icinga-${icingaVersion}/module/idoutils/db/pgsql/pgsql.sql",
requirement => Cmmi['icinga-pgsql'],
}
package { [
@ -119,12 +118,6 @@ file { '/etc/init.d/ido2db-pgsql':
require => Cmmi['icinga-pgsql']
}
exec { 'populate-icinga-pgsql-db':
unless => 'psql -U icinga -d icinga -c "SELECT * FROM icinga_dbversion;" &> /dev/null',
command => "sudo -u postgres psql -U icinga -d icinga < /usr/local/src/icinga-pgsql/icinga-${icingaVersion}/module/idoutils/db/pgsql/pgsql.sql",
require => [ Cmmi['icinga-pgsql'], Exec['create-pgsql-icinga-db'] ]
}
service { 'icinga-mysql':
ensure => running,
require => File['/etc/init.d/icinga-mysql']

View File

@ -0,0 +1,17 @@
define pgsql::database ($username, $password, $schemafile, $requirement) {
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']
}
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"] ]
}
}