From 647d5fda99f79f6af3d14765092510c19801e8d0 Mon Sep 17 00:00:00 2001 From: mh Date: Sat, 3 Oct 2009 15:19:11 +0200 Subject: [PATCH] refactor classes --- manifests/client.pp | 8 ++ manifests/init.pp | 122 ------------------------------ manifests/selinux.pp | 16 ---- manifests/server.pp | 13 ++++ manifests/server/base.pp | 71 +++++++++++++++++ manifests/server/centos.pp | 9 +++ manifests/server/clientpackage.pp | 15 ++++ manifests/server/gentoo.pp | 6 ++ 8 files changed, 122 insertions(+), 138 deletions(-) create mode 100644 manifests/client.pp delete mode 100644 manifests/selinux.pp create mode 100644 manifests/server.pp create mode 100644 manifests/server/base.pp create mode 100644 manifests/server/centos.pp create mode 100644 manifests/server/clientpackage.pp create mode 100644 manifests/server/gentoo.pp diff --git a/manifests/client.pp b/manifests/client.pp new file mode 100644 index 0000000..15234e6 --- /dev/null +++ b/manifests/client.pp @@ -0,0 +1,8 @@ +class mysql::client { + package{mysql: + ensure => present, + } + if $use_shorewall { + include shorewall::rules::out::mysql + } +} diff --git a/manifests/init.pp b/manifests/init.pp index 4ebfb4f..3d8d8e3 100644 --- a/manifests/init.pp +++ b/manifests/init.pp @@ -1,4 +1,3 @@ -# # mysql module # # Copyright (C) 2007 David Schmitt @@ -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', - } - -} diff --git a/manifests/selinux.pp b/manifests/selinux.pp deleted file mode 100644 index 1ec2e03..0000000 --- a/manifests/selinux.pp +++ /dev/null @@ -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': } -} diff --git a/manifests/server.pp b/manifests/server.pp new file mode 100644 index 0000000..25b0404 --- /dev/null +++ b/manifests/server.pp @@ -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 + } +} diff --git a/manifests/server/base.pp b/manifests/server/base.pp new file mode 100644 index 0000000..bc4380f --- /dev/null +++ b/manifests/server/base.pp @@ -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}" |>> +} diff --git a/manifests/server/centos.pp b/manifests/server/centos.pp new file mode 100644 index 0000000..98febb7 --- /dev/null +++ b/manifests/server/centos.pp @@ -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', + } + +} diff --git a/manifests/server/clientpackage.pp b/manifests/server/clientpackage.pp new file mode 100644 index 0000000..cf3bf57 --- /dev/null +++ b/manifests/server/clientpackage.pp @@ -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], + } +} diff --git a/manifests/server/gentoo.pp b/manifests/server/gentoo.pp new file mode 100644 index 0000000..b45394d --- /dev/null +++ b/manifests/server/gentoo.pp @@ -0,0 +1,6 @@ +class mysql::server::gentoo inherits mysql::server::base { + Package[mysql-server] { + alias => 'mysql', + category => 'dev-db', + } +}