switch hiera to pull its variables in parameterized classes instead of inline in the manifest

This commit is contained in:
Micah Anderson 2012-04-04 17:47:13 -04:00
parent 32fdce32d9
commit a55ce915da
5 changed files with 82 additions and 73 deletions

View file

@ -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
}
}

View file

@ -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
}
}

View file

@ -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':

View file

@ -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'] ],
}
}

View file

@ -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'] ],
}
}