Outsource Icinga (2) database creation into mysql::database

refs #6842
This commit is contained in:
Alexander Klimov 2014-08-04 13:40:11 +02:00
parent a4b7204e23
commit 8806583289
2 changed files with 25 additions and 14 deletions

View File

@ -8,21 +8,9 @@ Exec { path => '/bin:/usr/bin:/sbin' }
$icingaVersion = '1.11.2'
$icinga2Version = '2.0.0'
exec { 'create-mysql-icinga-db':
unless => 'mysql -uicinga -picinga icinga',
command => 'mysql -uroot -e "CREATE DATABASE icinga; \
GRANT SELECT,INSERT,UPDATE,DELETE ON icinga.* TO icinga@localhost \
IDENTIFIED BY \'icinga\';"',
require => Service['mysqld']
}
mysql::database { 'icinga': }
exec { 'create-mysql-icinga2-db':
unless => 'mysql -uicinga2 -picinga2 icinga2',
command => 'mysql -uroot -e "CREATE DATABASE icinga2; \
GRANT SELECT,INSERT,UPDATE,DELETE ON icinga2.* to icinga2@localhost \
IDENTIFIED BY \'icinga2\';"',
require => Service['mysqld']
}
mysql::database { 'icinga2': }
exec{ 'create-pgsql-icinga-db':
unless => 'sudo -u postgres psql -tAc "SELECT 1 FROM pg_roles WHERE rolname=\'icinga\'" | grep -q 1',

View File

@ -0,0 +1,23 @@
define mysql::database (
$username = 'UNDEF',
$password = 'UNDEF'
) {
include mysql
$user = $username ? {
/UNDEF/ => $name,
default => $username,
}
$pass = $password ? {
/UNDEF/ => $user,
default => $password,
}
exec { "create-mysql-${name}-db":
unless => "mysql -u${user} -p${pass} ${name}",
command => "mysql -uroot -e \"CREATE DATABASE ${name}; \
GRANT SELECT,INSERT,UPDATE,DELETE ON ${name}.* TO ${user}@localhost \
IDENTIFIED BY '${pass}';\"",
require => Service['mysqld']
}
}