refactor classes

This commit is contained in:
mh 2009-10-03 15:19:11 +02:00
parent 8100f49e32
commit 647d5fda99
8 changed files with 122 additions and 138 deletions

8
manifests/client.pp Normal file
View file

@ -0,0 +1,8 @@
class mysql::client {
package{mysql:
ensure => present,
}
if $use_shorewall {
include shorewall::rules::out::mysql
}
}

View file

@ -1,4 +1,3 @@
#
# mysql module
#
# Copyright (C) 2007 David Schmitt <david@schmitt.edv-bus.at>
@ -8,124 +7,3 @@
# Marcel Härry haerry+puppet(at)puzzle.ch
# Simon Josi josi+puppet(at)puzzle.ch
#
class mysql::server {
case $operatingsystem {
gentoo: { include mysql::server::gentoo }
centos: { include mysql::server::centos }
default: { include mysql::server::base }
}
if $selinux {
include mysql::selinux
}
if $use_munin {
include mysql::munin
}
}
class mysql::server::base {
package { mysql-server:
ensure => present,
}
file{'/etc/mysql/my.cnf':
source => [
"puppet://$server/files/mysql/${fqdn}/my.cnf",
"puppet://$server/files/mysql/my.cnf",
"puppet://$server/mysql/config/my.cnf.${operatingsystem}",
"puppet://$server/mysql/config/my.cnf"
],
ensure => file,
require => Package[mysql-server],
notify => Service[mysql],
owner => root, group => 0, mode => 0644;
}
file{'/var/lib/mysql/data':
ensure => directory,
require => Package[mysql-server],
before => File['/etc/mysql/my.cnf'],
owner => mysql, group => mysql, mode => 0755;
}
file{'/var/lib/mysql/data/ibdata1':
ensure => file,
require => Package[mysql-server],
before => File['/opt/bin/setmysqlpass.sh'],
owner => mysql, group => mysql, mode => 0660;
}
case $mysql_rootpw {
'': { fail("You need to define a mysql root password! Please set \$mysql_rootpw in your site.pp or host config") }
}
file{'/opt/bin/setmysqlpass.sh':
source => "puppet://$server/mysql/config/${operatingsystem}/setmysqlpass.sh",
require => Package[mysql-server],
owner => root, group => 0, mode => 0500;
}
file {'/root/.my.cnf':
content => template('mysql/root/my.cnf.erb'),
require => [ Package[mysql-server] ],
owner => root, group => 0, mode => 0400;
}
exec{'set_mysql_rootpw':
command => "/opt/bin/setmysqlpass.sh $mysql_rootpw",
unless => "mysqladmin -uroot status > /dev/null",
require => [ File['/opt/bin/setmysqlpass.sh'], Package[mysql-server] ],
}
file{'/etc/cron.d/mysql_backup.cron':
source => [ "puppet://$server/mysql/backup/mysql_backup.cron.${operatingsystem}",
"puppet://$server/mysql/backup/mysql_backup.cron" ],
require => [ Exec[set_mysql_rootpw], File['/root/.my.cnf'] ],
owner => root, group => 0, mode => 0600;
}
file{'/etc/cron.weekly/mysql_optimize_tables.rb':
source => "puppet://$server/mysql/optimize/optimize_tables.rb",
require => [ Exec[set_mysql_rootpw], File['/root/.my.cnf'] ],
owner => root, group => 0, mode => 0700;
}
service {mysql:
ensure => running,
enable => true,
hasstatus => true,
require => Package[mysql],
}
# Collect all databases and users
Mysql_database<<| tag == "mysql_${fqdn}" |>>
Mysql_user<<| tag == "mysql_${fqdn}" |>>
Mysql_grant<<| tag == "mysql_${fqdn}" |>>
}
class mysql::server::gentoo inherits mysql::server::base {
Package[mysql-server] {
alias => 'mysql',
category => 'dev-db',
}
}
class mysql::server::clientpackage inherits mysql::server::base {
package{mysql:
ensure => present,
}
File['/opt/bin/setmysqlpass.sh']{
require +> Package[mysql],
}
File['/root/.my.cnf']{
require +> Package[mysql],
}
Exec['set_mysql_rootpw']{
require +> Package[mysql],
}
File['/etc/cron.d/mysql_backup.cron']{
require +> Package[mysql],
}
}
class mysql::server::centos inherits mysql::server::clientpackage {
Service[mysql]{
name => 'mysqld',
}
File['/etc/mysql/my.cnf']{
path => '/etc/my.cnf',
}
}

View file

@ -1,16 +0,0 @@
# manifests/selinux.pp
class mysql::selinux {
case $operatingsystem {
gentoo: { include mysql::selinux::gentoo }
}
}
class mysql::selinux::gentoo {
package{'selinux-mysql':
ensure => present,
category => 'sec-policy',
require => Package[mysql],
}
selinux::loadmodule {'mysql': }
}

13
manifests/server.pp Normal file
View file

@ -0,0 +1,13 @@
class mysql::server {
case $operatingsystem {
gentoo: { include mysql::server::gentoo }
centos: { include mysql::server::centos }
default: { include mysql::server::base }
}
if $use_munin {
include mysql::munin
}
if $use_shorewall {
include shorewal::rules::mysql
}
}

71
manifests/server/base.pp Normal file
View file

@ -0,0 +1,71 @@
class mysql::server::base {
package { mysql-server:
ensure => present,
}
file{'/etc/mysql/my.cnf':
source => [
"puppet://$server/files/mysql/${fqdn}/my.cnf",
"puppet://$server/files/mysql/my.cnf",
"puppet://$server/mysql/config/my.cnf.${operatingsystem}",
"puppet://$server/mysql/config/my.cnf"
],
ensure => file,
require => Package[mysql-server],
notify => Service[mysql],
owner => root, group => 0, mode => 0644;
}
file{'/var/lib/mysql/data':
ensure => directory,
require => Package[mysql-server],
before => File['/etc/mysql/my.cnf'],
owner => mysql, group => mysql, mode => 0755;
}
file{'/var/lib/mysql/data/ibdata1':
ensure => file,
require => Package[mysql-server],
before => File['/opt/bin/setmysqlpass.sh'],
owner => mysql, group => mysql, mode => 0660;
}
case $mysql_rootpw {
'': { fail("You need to define a mysql root password! Please set \$mysql_rootpw in your site.pp or host config") }
}
file{'/opt/bin/setmysqlpass.sh':
source => "puppet://$server/mysql/config/${operatingsystem}/setmysqlpass.sh",
require => Package[mysql-server],
owner => root, group => 0, mode => 0500;
}
file {'/root/.my.cnf':
content => template('mysql/root/my.cnf.erb'),
require => [ Package[mysql-server] ],
owner => root, group => 0, mode => 0400;
}
exec{'set_mysql_rootpw':
command => "/opt/bin/setmysqlpass.sh $mysql_rootpw",
unless => "mysqladmin -uroot status > /dev/null",
require => [ File['/opt/bin/setmysqlpass.sh'], Package[mysql-server] ],
}
file{'/etc/cron.d/mysql_backup.cron':
source => [ "puppet://$server/mysql/backup/mysql_backup.cron.${operatingsystem}",
"puppet://$server/mysql/backup/mysql_backup.cron" ],
require => [ Exec[set_mysql_rootpw], File['/root/.my.cnf'] ],
owner => root, group => 0, mode => 0600;
}
file{'/etc/cron.weekly/mysql_optimize_tables.rb':
source => "puppet://$server/mysql/optimize/optimize_tables.rb",
require => [ Exec[set_mysql_rootpw], File['/root/.my.cnf'] ],
owner => root, group => 0, mode => 0700;
}
service {mysql:
ensure => running,
enable => true,
hasstatus => true,
require => Package[mysql],
}
# Collect all databases and users
Mysql_database<<| tag == "mysql_${fqdn}" |>>
Mysql_user<<| tag == "mysql_${fqdn}" |>>
Mysql_grant<<| tag == "mysql_${fqdn}" |>>
}

View file

@ -0,0 +1,9 @@
class mysql::server::centos inherits mysql::server::clientpackage {
Service[mysql]{
name => 'mysqld',
}
File['/etc/mysql/my.cnf']{
path => '/etc/my.cnf',
}
}

View file

@ -0,0 +1,15 @@
class mysql::server::clientpackage inherits mysql::server::base {
include mysql::client
File['/opt/bin/setmysqlpass.sh']{
require +> Package[mysql],
}
File['/root/.my.cnf']{
require +> Package[mysql],
}
Exec['set_mysql_rootpw']{
require +> Package[mysql],
}
File['/etc/cron.d/mysql_backup.cron']{
require +> Package[mysql],
}
}

View file

@ -0,0 +1,6 @@
class mysql::server::gentoo inherits mysql::server::base {
Package[mysql-server] {
alias => 'mysql',
category => 'dev-db',
}
}