From e42f400f38d955ae81a3312e3f1ca1cce72e3d2c Mon Sep 17 00:00:00 2001 From: Alexander Klimov Date: Tue, 5 Aug 2014 14:42:01 +0200 Subject: [PATCH] Outsource Icinga database creation and population into pgsql::database refs #6842 --- .vagrant-puppet/manifests/default.pp | 17 +++++------------ .../modules/pgsql/manifests/database.pp | 17 +++++++++++++++++ 2 files changed, 22 insertions(+), 12 deletions(-) create mode 100644 .vagrant-puppet/modules/pgsql/manifests/database.pp diff --git a/.vagrant-puppet/manifests/default.pp b/.vagrant-puppet/manifests/default.pp index ede5c5c36..94c868a89 100644 --- a/.vagrant-puppet/manifests/default.pp +++ b/.vagrant-puppet/manifests/default.pp @@ -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'] diff --git a/.vagrant-puppet/modules/pgsql/manifests/database.pp b/.vagrant-puppet/modules/pgsql/manifests/database.pp new file mode 100644 index 000000000..54703f83a --- /dev/null +++ b/.vagrant-puppet/modules/pgsql/manifests/database.pp @@ -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"] ] + } +}