Skip to content

Commit

Permalink
fix #302 debian dbconfig for mysql and pgsql, add class debian::dbconfig
Browse files Browse the repository at this point in the history
  • Loading branch information
lbetz committed Jun 20, 2017
1 parent 47028a4 commit c3bc0e2
Show file tree
Hide file tree
Showing 4 changed files with 113 additions and 51 deletions.
18 changes: 13 additions & 5 deletions examples/init_idopgsql.pp
Original file line number Diff line number Diff line change
@@ -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'],
}
82 changes: 82 additions & 0 deletions manifests/debian.pp
Original file line number Diff line number Diff line change
@@ -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

}
55 changes: 9 additions & 46 deletions manifests/feature/idomysql.pp
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
9 changes: 9 additions & 0 deletions manifests/feature/idopgsql.pp
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit c3bc0e2

Please sign in to comment.