diff --git a/README.md b/README.md index 8b9fa8b5..62203003 100644 --- a/README.md +++ b/README.md @@ -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/ { diff --git a/manifests/init.pp b/manifests/init.pp index 7482b714..1a1f884a 100644 --- a/manifests/init.pp +++ b/manifests/init.pp @@ -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 @@ $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 @@ 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) diff --git a/manifests/initialize.pp b/manifests/initialize.pp new file mode 100644 index 00000000..f9854b8b --- /dev/null +++ b/manifests/initialize.pp @@ -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." + } + } + } +} + diff --git a/manifests/params.pp b/manifests/params.pp index 7b8d0cf9..72363476 100644 --- a/manifests/params.pp +++ b/manifests/params.pp @@ -39,6 +39,7 @@ $web_db_prefix = 'icingaweb2_' $web_db_user = 'icingaweb2' $web_type = 'db' + $initialize = false case $::osfamily { 'RedHat': { diff --git a/spec/classes/icingaweb2_spec.rb b/spec/classes/icingaweb2_spec.rb index dfaab20c..49044eb2 100644 --- a/spec/classes/icingaweb2_spec.rb +++ b/spec/classes/icingaweb2_spec.rb @@ -280,6 +280,15 @@ 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_"' } }