Feature: initialize database if preferred so a working icingaweb2 instance can be started automatically
This commit is contained in:
parent
df2c66896a
commit
df99507221
5 changed files with 58 additions and 0 deletions
|
@ -52,6 +52,14 @@ Icinga Web 2 is the next generation open source monitoring web interface, framew
|
|||
}
|
||||
}
|
||||
|
||||
### Initialize db
|
||||
|
||||
node /box/ {
|
||||
class { 'icingaweb2':
|
||||
initialize => true,
|
||||
}
|
||||
}
|
||||
|
||||
### Manage repository
|
||||
|
||||
node /box/ {
|
||||
|
|
|
@ -164,6 +164,8 @@
|
|||
# $web_type::
|
||||
# Default:
|
||||
#
|
||||
# $initialize:: Whether or not to initialize a db scheme and a user
|
||||
# Default : false
|
||||
class icingaweb2 (
|
||||
$admin_permissions = $::icingaweb2::params::admin_permissions,
|
||||
$admin_users = $::icingaweb2::params::admin_users,
|
||||
|
@ -217,10 +219,12 @@ class icingaweb2 (
|
|||
$web_db_user = $::icingaweb2::params::web_db_user,
|
||||
$web_root = $::icingaweb2::params::web_root,
|
||||
$web_type = $::icingaweb2::params::web_type,
|
||||
$initialize = $::icingaweb2::params::initialize,
|
||||
) inherits ::icingaweb2::params {
|
||||
class { '::icingaweb2::preinstall': } ->
|
||||
class { '::icingaweb2::install': } ->
|
||||
class { '::icingaweb2::config': } ->
|
||||
class { '::icingaweb2::initialize': } ->
|
||||
Class['::icingaweb2']
|
||||
|
||||
validate_absolute_path($config_dir)
|
||||
|
@ -229,6 +233,7 @@ class icingaweb2 (
|
|||
validate_array($pkg_list)
|
||||
validate_bool($config_dir_recurse)
|
||||
validate_bool($manage_repo)
|
||||
validate_bool($initialize)
|
||||
validate_slength($config_dir_mode, 4)
|
||||
validate_slength($config_file_mode, 4)
|
||||
validate_string($admin_permissions)
|
||||
|
|
35
manifests/initialize.pp
Normal file
35
manifests/initialize.pp
Normal file
|
@ -0,0 +1,35 @@
|
|||
# == Class icingaweb2::initialize
|
||||
#
|
||||
# This class is used to initialize a default icingaweb2 db and user
|
||||
# Depends on the pupppetlabs-mysql module
|
||||
class icingaweb2::initialize {
|
||||
if $::icingaweb2::initialize {
|
||||
case $::operatingsystem {
|
||||
'RedHat', 'CentOS': {
|
||||
case $::icingaweb2::web_db {
|
||||
'mysql': {
|
||||
exec { 'create db scheme':
|
||||
command => "mysql -u ${::icingaweb2::web_db_user} -p${::icingaweb2::web_db_pass} ${::icingaweb2::web_db_name} < /usr/share/doc/icingaweb2/schema/mysql.schema.sql",
|
||||
onlyif => 'test -f /root/.my.cnf',
|
||||
notify => Exec['create web user']
|
||||
}
|
||||
|
||||
exec { 'create web user':
|
||||
command => "mysql --defaults-file='/root/.my.cnf' ${::icingaweb2::web_db_name} -e \" INSERT INTO icingaweb_user (name, active, password_hash) VALUES ('icingaadmin', 1, '\\\$1\\\$EzxLOFDr\\\$giVx3bGhVm4lDUAw6srGX1');\"",
|
||||
refreshonly => true,
|
||||
}
|
||||
}
|
||||
|
||||
default: {
|
||||
fail "DB type ${::icingaweb2::web_db} not supported yet"
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
default: {
|
||||
fail "Managing repositories for ${::operatingsystem} is not supported."
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -39,6 +39,7 @@ class icingaweb2::params {
|
|||
$web_db_prefix = 'icingaweb2_'
|
||||
$web_db_user = 'icingaweb2'
|
||||
$web_type = 'db'
|
||||
$initialize = false
|
||||
|
||||
case $::osfamily {
|
||||
'RedHat': {
|
||||
|
|
|
@ -280,6 +280,15 @@ describe 'icingaweb2', :type => :class do
|
|||
pending
|
||||
end
|
||||
|
||||
describe 'with parameter: initialize => true' do
|
||||
context 'Distro: CentOS' do
|
||||
let (:params) { { :initialize => true } }
|
||||
let (:facts) { centos_facts }
|
||||
|
||||
it { should contain_icingaweb2__initialize }
|
||||
end
|
||||
end
|
||||
|
||||
describe 'with parameter: web_db_host' do
|
||||
let (:params) { { :web_db_host => '"_web_db_host_"' } }
|
||||
|
||||
|
|
Loading…
Reference in a new issue