From a55ce915da835e23b24054aa493d756f85f3b60d Mon Sep 17 00:00:00 2001 From: Micah Anderson Date: Wed, 4 Apr 2012 17:47:13 -0400 Subject: switch hiera to pull its variables in parameterized classes instead of inline in the manifest --- manifests/client.pp | 6 +++--- manifests/server.pp | 48 +++++++++++++++++++++-------------------- manifests/server/base.pp | 13 ++++++----- manifests/server/cron/backup.pp | 40 ++++++++++++++++++---------------- manifests/server/nagios.pp | 48 +++++++++++++++++++++-------------------- 5 files changed, 82 insertions(+), 73 deletions(-) diff --git a/manifests/client.pp b/manifests/client.pp index 8d2280f..005d8e8 100644 --- a/manifests/client.pp +++ b/manifests/client.pp @@ -1,12 +1,12 @@ -class mysql::client { +class mysql::client ( $use_shorewall = hiera('use_shorewall',false) { case $::operatingsystem { debian: { include mysql::client::debian } default: { include mysql::client::base } } - if hiera('use_shorewall',false) { + if $use_shorewall { include shorewall::rules::out::mysql } - + } diff --git a/manifests/server.pp b/manifests/server.pp index 964d7cb..3ea038b 100644 --- a/manifests/server.pp +++ b/manifests/server.pp @@ -1,27 +1,29 @@ -class mysql::server { +class mysql::server ( + $use_munin = hiera('use_nagios',false), + $use_shorewall = hiera('use_shorewall',false) +) { + case $::operatingsystem { + gentoo: { include mysql::server::gentoo } + centos: { include mysql::server::centos } + debian: { include mysql::server::debian } + default: { include mysql::server::base } + } - case $::operatingsystem { - gentoo: { include mysql::server::gentoo } - centos: { include mysql::server::centos } - debian: { include mysql::server::debian } - default: { include mysql::server::base } - } + if $use_munin { + case $::operatingsystem { + debian: { include mysql::server::munin::debian } + default: { include mysql::server::munin::default } + } + } - if hiera('use_munin',false) { - case $::operatingsystem { - debian: { include mysql::server::munin::debian } - default: { include mysql::server::munin::default } - } - } + if $use_nagios { + case $nagios_check_mysql { + false: { info("We don't do nagioschecks for mysql on ${::fqdn}" ) } + default: { include mysql::server::nagios } + } + } - if hiera('use_nagios',false) { - case hiera('nagios_check_mysql',false) { - false: { info("We don't do nagioschecks for mysql on ${::fqdn}" ) } - default: { include mysql::server::nagios } - } - } - - if hiera('use_shorewall',false) { - include shorewall::rules::mysql - } + if $use_shorewall { + include shorewall::rules::mysql + } } diff --git a/manifests/server/base.pp b/manifests/server/base.pp index 75f5725..529696f 100644 --- a/manifests/server/base.pp +++ b/manifests/server/base.pp @@ -1,4 +1,7 @@ -class mysql::server::base { +class mysql::server::base( + $mysql_backup_cron = hiera('mysql_backup_cron', false), + $mysql_optimize_cron = hiera('mysql_optimize_cron', false) +) { package { mysql-server: ensure => present, } @@ -57,12 +60,12 @@ class mysql::server::base { refreshonly => true, } - if hiera('mysql_backup_cron',false) { - include mysql::server::cron::backup + if ($mysql_backup_cron) { + include mysql::server::cron::backup } - if hiera('mysql_optimize_cron',false) { - include mysql::server::cron::optimize + if $mysql_optimize_cron) { + include mysql::server::cron::optimize } service { 'mysql': diff --git a/manifests/server/cron/backup.pp b/manifests/server/cron/backup.pp index 4b5c3e5..b105f1b 100644 --- a/manifests/server/cron/backup.pp +++ b/manifests/server/cron/backup.pp @@ -1,22 +1,24 @@ -class mysql::server::cron::backup { - $mysql_backup_dir = hiera('mysql_backup_dir','/var/backups/mysql') - case hiera('mysql_manage_backup_dir',true) { - false: { info("We don't manage the mysql_backup_dir") } - default: { - file { 'mysql_backup_dir': - path => hiera('mysql_backup_dir','/var/backups/mysql'), - ensure => directory, - before => Cron['mysql_backup_cron'], - owner => root, group => 0, mode => 0700; - } - } - } +class mysql::server::cron::backup ( + $mysql_backup_dir = hiera('mysql_backup_dir','/var/backups/mysql'), + $mysql_manage_backup_dir = hiera('mysql_manage_backup_dir',true) +) { + case $mysql_manage_backup_dir { + false: { info("We don't manage the mysql_backup_dir") } + default: { + file { 'mysql_backup_dir': + path => $mysql_backup_dir, + ensure => directory, + before => Cron['mysql_backup_cron'], + owner => root, group => 0, mode => 0700; + } + } + } - cron { 'mysql_backup_cron': - command => "/usr/bin/mysqldump --default-character-set=utf8 --all-databases --all --flush-logs --lock-tables --single-transaction | gzip > ${mysql_backup_dir}/mysqldump.sql.gz && chmod 600 ${mysql_backup_dir}/mysqldump.sql.gz", - user => 'root', - minute => 0, - hour => 1, - require => [ Exec['mysql_set_rootpw'], File['mysql_root_cnf'] ], + cron { 'mysql_backup_cron': + command => "/usr/bin/mysqldump --default-character-set=utf8 --all-databases --all --flush-logs --lock-tables --single-transaction | gzip > ${mysql_backup_dir}/mysqldump.sql.gz && chmod 600 ${mysql_backup_dir}/mysqldump.sql.gz", + user => 'root', + minute => 0, + hour => 1, + require => [ Exec['mysql_set_rootpw'], File['mysql_root_cnf'] ], } } diff --git a/manifests/server/nagios.pp b/manifests/server/nagios.pp index 26644db..40bd0ee 100644 --- a/manifests/server/nagios.pp +++ b/manifests/server/nagios.pp @@ -1,28 +1,30 @@ # manifests/server/nagios.pp -class mysql::server::nagios { - # Flip this variable if you need to check MySQL through check_ssh or check_nrpe, - # in that case you will have to manually define nagios::service::mysql - if (hiera('nagios_mysql_notcp',false) != true) { - $nagios_mysql_user = 'nagios@%' - nagios::service::mysql { 'connection-time': - check_hostname => $::fqdn, - require => Mysql_grant[$nagios_mysql_user], - } - } - else { - $nagios_mysql_user = 'nagios@localhost' - } +class mysql::server::nagios ( + $nagios_mysql_notcp = hiera('nagios_mysql_notcp',false) +) { + # Flip this variable if you need to check MySQL through check_ssh or check_nrpe, + # in that case you will have to manually define nagios::service::mysql + if ($nagios_mysql_notcp != true) { + $nagios_mysql_user = 'nagios@%' + nagios::service::mysql { 'connection-time': + check_hostname => $::fqdn, + require => Mysql_grant[$nagios_mysql_user], + } + } + else { + $nagios_mysql_user = 'nagios@localhost' + } - mysql_user{$nagios_mysql_user: - password_hash => trocla("mysql_nagios_${::fqdn}",'mysql','length: 32'), - require => Package['mysql'], - } + mysql_user{$nagios_mysql_user: + password_hash => trocla("mysql_nagios_${::fqdn}",'mysql','length: 32'), + require => Package['mysql'], + } - # repl_client_priv is needed to check the replication slave status - # modes: slave-lag, slave-io-running and slave-sql-running - mysql_grant{$nagios_mysql_user: - privileges => [ 'select_priv', 'repl_client_priv' ], - require => [ Mysql_user[$nagios_mysql_user], Package['mysql'] ], - } + # repl_client_priv is needed to check the replication slave status + # modes: slave-lag, slave-io-running and slave-sql-running + mysql_grant{$nagios_mysql_user: + privileges => [ 'select_priv', 'repl_client_priv' ], + require => [ Mysql_user[$nagios_mysql_user], Package['mysql'] ], + } } -- cgit v1.2.3