Created config class and extended params.

It makes way more sense to just allow it as a 
class param.

Also added some additional config for setting bind
address and port.

Added management of /etc/mysql/my.cnf

Documented a dependency on create_resources 0.0.1
This commit is contained in:
Dan Bode 2011-06-22 11:38:11 -07:00
parent dbcdaf98d1
commit a24881a682
6 changed files with 88 additions and 43 deletions

View file

@ -6,3 +6,5 @@ license 'Apache'
summary 'Mysql module'
description 'Mysql module'
project_page 'http://github.com/puppetlabs/puppetlabs-mysql'
dependency 'puppetlasb/create_resources', '>= 1.2.0'

41
manifests/config.pp Normal file
View file

@ -0,0 +1,41 @@
class mysql::config(
$root_password = 'UNSET',
$old_root_password = '',
$bind_address = '127.0.0.1',
$port = 3306
) {
# manage root password if it is set
if ! $root_password == 'UNSET' {
$root_password = $config_hash['root_password']
case $old_root_password {
'': {$old_pw=''}
default: {$old_pw="-p${old_root_password}"}
}
exec{ 'set_mysql_rootpw':
command => "mysqladmin -u root ${old_pw} password ${root_password}",
#logoutput => on_failure,
logoutput => true,
unless => "mysqladmin -u root -p${root_password} status > /dev/null",
path => '/usr/local/sbin:/usr/bin',
require => [Package['mysql-server'], Service['mysqld']],
before => File['/root/.my.cnf', '/etc/my.cnf'],
notify => Exec['mysqld-restart'],
}
}
File {
owner => 'root',
group => 'root',
notify => Exec['mysqld-restart'],
require => Package['mysql-server']
}
file{'/root/.my.cnf':
mode => '0400',
content => template('mysql/my.cnf.pass.erb'),
}
file { '/etc/mysql/my.cnf':
mode => '0400',
content => template('mysql/my.cnf.erb'),
}
}

View file

@ -17,22 +17,16 @@
#
class mysql::server(
$service_name = $mysql::params::service_name,
$root_password = undef,
$old_root_password = undef,
$config_hash = {},
$package_name = 'mysql-server'
) inherits mysql::params {
case $operatingsystem {
'centos', 'redhat', 'fedora': {
class { 'mysql::server::redhat':
root_password => $root_password,
old_root_password => $old_root_password,
}
}
'ubuntu', 'debian': {
# there is not any debian specific config yet
}
# automatically create a class to deal with
# configuration
$hash = {
"mysql::config" => $config_hash
}
create_resources("class", $hash)
package{'mysql-server':
name => $package_name,

View file

@ -1,27 +0,0 @@
class mysql::server::redhat(
$root_password,
$old_root_password = ''
) {
case $old_root_password {
'': {$old_pw=''}
default: {$old_pw="-p${old_root_password}"}
}
exec{ 'set_mysql_rootpw':
command => "mysqladmin -u root ${old_pw} password ${root_password}",
#logoutput => on_failure,
logoutput => true,
unless => "mysqladmin -u root -p${root_password} status > /dev/null",
path => '/usr/local/sbin:/usr/bin',
require => [Package['mysql-server'], Service['mysqld']],
before => File['/root/.my.cnf', '/etc/my.cnf'],
notify => Exec['mysqld-restart'],
}
file{['/root/.my.cnf', '/etc/my.cnf']:
owner => 'root',
group => 'root',
mode => '0400',
content => template('mysql/my.cnf.erb'),
notify => Exec['mysqld-restart'],
require => Package['mysql-server'],
}
}

View file

@ -1,4 +1,33 @@
[client]
user=root
host=localhost
password=<%= root_password -%>
port = <%= port %>
socket = /var/run/mysqld/mysqld.sock
[mysqld_safe]
socket = /var/run/mysqld/mysqld.sock
nice = 0
[mysqld]
user = mysql
socket = /var/run/mysqld/mysqld.sock
port = <%= port %>
basedir = /usr
datadir = /var/lib/mysql
tmpdir = /tmp
skip-external-locking
bind-address = <%= bind_address %>
key_buffer = 16M
max_allowed_packet = 16M
thread_stack = 192K
thread_cache_size = 8
myisam-recover = BACKUP
query_cache_limit = 1M
query_cache_size = 16M
log_error = /var/log/mysql/error.log
expire_logs_days = 10
max_binlog_size = 100M
[mysqldump]
quick
quote-names
max_allowed_packet = 16M
[mysql]
[isamchk]
key_buffer = 16M
!includedir /etc/mysql/conf.d/

View file

@ -0,0 +1,6 @@
[client]
user=root
host=localhost
<% unless root_password == 'UNSET' -%>
password=<%= root_password %>
<% end -%>