diff --git a/examples/init_idopgsql.pp b/examples/init_idopgsql.pp index fcbd75d55..c768b7891 100644 --- a/examples/init_idopgsql.pp +++ b/examples/init_idopgsql.pp @@ -1,11 +1,19 @@ +include ::postgresql::server + +postgresql::server::db { 'icinga2': + user => 'icinga2', + password => postgresql_password('icinga2', 'supersecret'), +} + class{ 'icinga2': manage_repo => true, } class{ 'icinga2::feature::idopgsql': - host => "127.0.0.1", - user => "icinga2", - password => "icinga2", - database => "icinga2", - import_schema => true + host => "127.0.0.1", + user => "icinga2", + password => "supersecret", + database => "icinga2", + import_schema => true, + require => Postgresql::Server::Db['icinga2'], } diff --git a/manifests/debian.pp b/manifests/debian.pp new file mode 100644 index 000000000..9239edcef --- /dev/null +++ b/manifests/debian.pp @@ -0,0 +1,82 @@ +class icinga2::debian::dbconfig( + $dbtype, + $dbserver, + $dbport, + $dbname, + $dbuser, + $dbpass, + $ssl = false, +) { + + if defined($caller_module_name) and $module_name != $caller_module_name and $caller_module_name != '' { + fail("icinga2::debian::dbconfig is a private define resource of the module icinga2, you're not permitted to use it.") + } + + validate_re($dbtype, [ '^mysql$', '^pgsql$' ], + "${dbtype} isn't supported. Valid values are 'mysql' and 'pgsql'.") + validate_string($dbserver) + validate_integer($dbport) + validate_string($dbname) + validate_string($dbuser) + validate_string($dbpass) + validate_bool($ssl) + + # dbconfig config for Debian or Ubuntu + if $::osfamily == 'debian' { + + include ::icinga2::params + + case $dbtype { + 'mysql': { + $default_port = 3306 + $path = "/etc/dbconfig-common/${::icinga2::params::ido_mysql_package}.conf" + } + 'pgsql': { + $default_port = 5432 + $path = "/etc/dbconfig-common/${::icinga2::params::ido_pgsql_package}.conf" + } + } + + file_line { "dbc-${dbtype}-dbuser": + path => $path, + line => "dbc_dbuser='${dbuser}'", + match => '^dbc_dbuser\s*=', + } + file_line { "dbc-${dbtype}-dbpass": + path => $path, + line => "dbc_dbpass='${dbpass}'", + match => '^dbc_dbpass\s*=', + } + file_line { "dbc-${dbtype}-dbname": + path => $path, + line => "dbc_dbname='${dbname}'", + match => '^dbc_dbname\s*=', + } + # only set host if isn't the default + if $dbserver != '127.0.0.1' and $dbserver != 'localhost' { + file_line { "dbc-${dbtype}-dbserver": + path => $path, + line => "dbc_dbserver='${dbserver}'", + match => '^dbc_dbserver\s*=', + } + } + # only set port if isn't the default + if $dbport != $default_port { + file_line { "dbc-${dbtype}-dbport": + path => $path, + line => "dbc_dbport='${dbport}'", + match => '^dbc_dbport\s*=', + } + } + # set ssl + if $ssl { + file_line { "dbc-${dbtype}-ssl": + path => $path, + line => "dbc_ssl='true'", + match => '^dbc_ssl\s*=', + } + } + + } # debian dbconfig + +} diff --git a/manifests/feature/idomysql.pp b/manifests/feature/idomysql.pp index b77c88a26..4ca8ac069 100644 --- a/manifests/feature/idomysql.pp +++ b/manifests/feature/idomysql.pp @@ -320,52 +320,15 @@ ensure => installed, before => Icinga2::Feature['ido-mysql'], } - - # dbconfig config for Debian or Ubuntu - if $::osfamily == 'debian' { - file_line { "dbc-${ido_mysql_package}-install": - path => "/etc/dbconfig-common/${ido_mysql_package}.conf", - line => "dbc_install='false'", - match => '^dbc_install\s*=', - require => Package[$ido_mysql_package]; - } - file_line { "dbc-${ido_mysql_package}-dbtype": - path => "/etc/dbconfig-common/${ido_mysql_package}.conf", - line => "dbc_dbtype='mysql'", - match => '^dbc_dbtype\s*=', - require => Package[$ido_mysql_package]; - } - file_line { "dbc-${ido_mysql_package}-dbuser": - path => "/etc/dbconfig-common/${ido_mysql_package}.conf", - line => "dbc_dbuser='${user}'", - match => '^dbc_dbuser\s*=', - require => Package[$ido_mysql_package]; - } - file_line { "dbc-${ido_mysql_package}-dbpass": - path => "/etc/dbconfig-common/${ido_mysql_package}.conf", - line => "dbc_dbpass='${password}'", - match => '^dbc_dbpass\s*=', - require => Package[$ido_mysql_package]; - } - file_line { "dbc-${ido_mysql_package}-dbname": - path => "/etc/dbconfig-common/${ido_mysql_package}.conf", - line => "dbc_dbname='${database}'", - match => '^dbc_dbname\s*=', - require => Package[$ido_mysql_package]; - } - file_line { "dbc-${ido_mysql_package}-dbserver": - path => "/etc/dbconfig-common/${ido_mysql_package}.conf", - line => "dbc_dbserver='${host}'", - match => '^dbc_dbserver\s*=', - require => Package[$ido_mysql_package]; - } - file_line { "dbc-${ido_mysql_package}-dbport": - path => "/etc/dbconfig-common/${ido_mysql_package}.conf", - line => "dbc_dbport='${port}'", - match => '^dbc_dbport\s*=', - require => Package[$ido_mysql_package]; - } - } # debian dbconfig + -> + class { '::icinga2::debian::dbconfig': + dbtype => 'mysql', + dbserver => $host, + dbport => $port, + dbname => $database, + dbuser => $user, + dbpass => $password, + } } # import db schema diff --git a/manifests/feature/idopgsql.pp b/manifests/feature/idopgsql.pp index 66e7b72dc..10629c0d9 100644 --- a/manifests/feature/idopgsql.pp +++ b/manifests/feature/idopgsql.pp @@ -137,6 +137,15 @@ ensure => installed, before => Icinga2::Feature['ido-pgsql'], } + -> + class { '::icinga2::debian::dbconfig': + dbtype => 'pgsql', + dbserver => $host, + dbport => $port, + dbname => $database, + dbuser => $user, + dbpass => $password, + } } # import db schema