Skip to content

Commit

Permalink
Feature: initialize database if preferred so a working icingaweb2 ins…
Browse files Browse the repository at this point in the history
…tance can be started automatically
  • Loading branch information
visibilityspots committed Dec 14, 2015
1 parent df2c668 commit df99507
Show file tree
Hide file tree
Showing 5 changed files with 58 additions and 0 deletions.
8 changes: 8 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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/ {
Expand Down
5 changes: 5 additions & 0 deletions manifests/init.pp
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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)
Expand All @@ -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)
Expand Down
35 changes: 35 additions & 0 deletions manifests/initialize.pp
Original file line number Diff line number Diff line change
@@ -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');\"",

This comment has been minimized.

Copy link
@solud

solud Jan 7, 2016

What password is this? Why not use variable expansion here?

This comment has been minimized.

Copy link
@visibilityspots

visibilityspots Jan 7, 2016

Author Contributor

It's the default PW of icingaweb2 described in their documentation.

Didn't made a variable of it since you can change it afterwards in the GUI like done when manually installing icingaweb2..

refreshonly => true,
}
}

default: {
fail "DB type ${::icingaweb2::web_db} not supported yet"
}
}
}

default: {
fail "Managing repositories for ${::operatingsystem} is not supported."
}
}
}
}

1 change: 1 addition & 0 deletions manifests/params.pp
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@
$web_db_prefix = 'icingaweb2_'
$web_db_user = 'icingaweb2'
$web_type = 'db'
$initialize = false

case $::osfamily {
'RedHat': {
Expand Down
9 changes: 9 additions & 0 deletions spec/classes/icingaweb2_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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_"' } }

Expand Down

0 comments on commit df99507

Please sign in to comment.