diff --git a/README.md b/README.md index db22435..127d15d 100644 --- a/README.md +++ b/README.md @@ -30,7 +30,7 @@ longer work with the previous classes and configuration as before. We've attempted to handle backwards compatibility automatically by adding a `attempt_compatibility_mode` parameter to the main mysql class. If you set this to true it will attempt to map your previous parameters into the new -mysql::globals class. +mysql::server class. ###WARNING @@ -49,27 +49,24 @@ live. Even if it's just a no-op and a manual comparision. Please be careful! If you just want a server installing with the default options you can run include '::mysql::server'. If you need to customize options, such as the root -password or /etc/my.cnf settings then you can also include mysql::globals and +password or /etc/my.cnf settings then you can also include mysql::server and pass in an override hash as seen below: ```puppet -class { '::mysql::globals': +class { '::mysql::server': override_options => { 'mysqld' => { 'max_connections' => '1024' } } } ``` ##Usage -The interactions with this module are split between mysql::globals and several -other classes, mysql::server, mysql::client, and mysql::bindings. +All interaction for the server is done via mysql::server. To install the +client you use mysql::client, and to install bindings you can use +mysql::bindings. -###mysql::globals +###Overrides -This class exists as a way to easily share values between the other mysql -classes. You can pass an override_options into this class to replace elements -of the existing default hash. - -The hash structure for overrides is as follows: +The hash structure for overrides in mysql::server is as follows: ```puppet override_options = { @@ -91,7 +88,7 @@ care if thing is alone or set to a value, it'll happily accept both. To add custom mysql configuration you can drop additional files into /etc/mysql/conf.d/ in order to override settings or add additional ones (if you -choose not to use override_options in mysql::globals). This location is +choose not to use override_options in mysql::server). This location is hardcoded into the my.cnf template file. ##Reference @@ -99,7 +96,6 @@ hardcoded into the my.cnf template file. ###Classes ####Public classes -* mysql::globals: Settings and customizations for MySQL. * mysql::server: Installs and configures MySQL. * mysql::server::account_security: Deletes default MySQL accounts. * mysql::server::monitor: Sets up a monitoring user. @@ -121,7 +117,15 @@ hardcoded into the my.cnf template file. ###Parameters -####mysql::globals +####mysql::server + +#####`root_password` + +What is the MySQL root password. Puppet will attempt to set it to this and update /root/.my.cnf. + +#####`old_root_password` + +What was the previous root password (REQUIRED if you wish to change the root password via Puppet.) #####`override_options` @@ -158,16 +162,6 @@ Should the service be restarted when things change? What is the group used for root? -####mysql::server - -#####`root_password` - -What is the MySQL root password. Puppet will attempt to set it to this and update /root/.my.cnf. - -#####`old_root_password` - -What was the previous root password (REQUIRED if you wish to change the root password via Puppet.) - #####`package_ensure` What to set the package to. Can be present, absent, or version. diff --git a/manifests/bindings.pp b/manifests/bindings.pp index d06b542..88c4903 100644 --- a/manifests/bindings.pp +++ b/manifests/bindings.pp @@ -22,7 +22,7 @@ class mysql::bindings ( $ruby_package_ensure = $mysql::params::ruby_package_ensure, $ruby_package_name = $mysql::params::ruby_package_name, $ruby_package_provider = $mysql::params::ruby_package_provider -) inherits mysql::globals { +) inherits mysql::params { if $java_enable { include '::mysql::bindings::java' } if $perl_enable { include '::mysql::bindings::perl' } diff --git a/manifests/client.pp b/manifests/client.pp index 40e40c9..0aee9a7 100644 --- a/manifests/client.pp +++ b/manifests/client.pp @@ -1,7 +1,7 @@ # class mysql::client ( $bindings_enable = false, -) inherits mysql::globals { +) inherits mysql::params { include '::mysql::client::install' diff --git a/manifests/client/install.pp b/manifests/client/install.pp index 194556a..d380ec6 100644 --- a/manifests/client/install.pp +++ b/manifests/client/install.pp @@ -1,6 +1,6 @@ class mysql::client::install( - $package_name = $mysql::globals::client_package_name, - $package_ensure = $mysql::globals::client_package_ensure + $package_name = $mysql::params::client_package_name, + $package_ensure = $mysql::params::client_package_ensure ) { package { 'mysql_client': diff --git a/manifests/globals.pp b/manifests/globals.pp deleted file mode 100644 index c10a5c4..0000000 --- a/manifests/globals.pp +++ /dev/null @@ -1,70 +0,0 @@ -# See README.md for more details. -class mysql::globals ( - $config_file = $mysql::params::config_file, - $manage_config_file = $mysql::params::manage_config_file, - $old_root_password = $mysql::params::old_root_password, - $override_options = {}, - $purge_conf_dir = $mysql::params::purge_conf_dir, - $restart = $mysql::params::restart, - $root_group = $mysql::params::root_group, -) inherits mysql::params { - - case $::operatingsystem { - 'Ubuntu': { - $service_provider = upstart - } - default: { - $service_provider = undef - } - } - - $default_options = { - 'client' => { - 'port' => '3306', - 'socket' => $mysql::params::socket, - }, - 'mysqld_safe' => { - 'nice' => '0', - 'log_error' => $mysql::params::log_error, - 'socket' => $mysql::params::socket, - }, - 'mysqld' => { - 'basedir' => $mysql::params::basedir, - 'bind_address' => '127.0.0.1', - 'datadir' => $mysql::params::datadir, - 'expire_logs_days' => '10', - 'key_buffer' => '16M', - 'log_error' => $mysql::params::log_error, - 'max_allowed_packet' => '16M', - 'max_binlog_size' => '100M', - 'max_connections' => '151', - 'myisam_recover' => 'BACKUP', - 'pid_file' => $mysql::params::pidfile, - 'port' => '3306', - 'query_cache_limit' => '1M', - 'query_cache_size' => '16M', - 'skip-external-locking' => true, - 'socket' => $mysql::params::socket, - 'ssl' => false, - 'ssl-ca' => $mysql::params::ssl_ca, - 'ssl-cert' => $mysql::params::ssl_cert, - 'ssl-key' => $mysql::params::ssl_key, - 'thread_cache_size' => '8', - 'thread_stack' => '256K', - 'tmpdir' => $mysql::params::tmpdir, - 'user' => 'mysql', - }, - 'mysqldump' => { - 'max_allowed_packets' => '16M', - 'quick' => true, - 'quote-names' => true, - }, - 'isamchk' => { - 'key_buffer' => '16M', - }, - } - -# Create a merged together set of options. Rightmost hashes win over left. -$options = merge($default_options, $override_options) - -} diff --git a/manifests/init.pp b/manifests/init.pp index 4dfee6b..48ae694 100644 --- a/manifests/init.pp +++ b/manifests/init.pp @@ -37,7 +37,7 @@ class mysql( if $attempt_compatibility_mode { notify { "An attempt has been made below to automatically apply your custom - settings to mysql::globals. Please verify this works in a safe test + settings to mysql::server. Please verify this works in a safe test environment.": } $override_options = { @@ -81,20 +81,20 @@ class mysql( $filtered_options = mysql_strip_hash($override_options) validate_hash($filtered_options) notify { $filtered_options: } - class { 'mysql::globals': + class { 'mysql::server': override_options => $filtered_options, } } else { fail("ERROR: This class has been deprecated and the functionality moved - into mysql::globals. If you run mysql::server without correctly calling - mysql:: globals with the new override_options hash syntax you will revert + into mysql::server. If you run mysql::server without correctly calling + mysql:: server with the new override_options hash syntax you will revert your MySQL to the stock settings. Do not proceed without removing this - class and using mysql::globals correctly. + class and using mysql::server correctly. If you are brave you may set attempt_compatibility_mode in this class which attempts to automap the previous settings to appropriate calls to - mysql::globals") + mysql::server") } } diff --git a/manifests/params.pp b/manifests/params.pp index f0f75b2..c1b09a5 100644 --- a/manifests/params.pp +++ b/manifests/params.pp @@ -166,4 +166,59 @@ class mysql::params { } } + case $::operatingsystem { + 'Ubuntu': { + $service_provider = upstart + } + default: { + $service_provider = undef + } + } + + $default_options = { + 'client' => { + 'port' => '3306', + 'socket' => $mysql::params::socket, + }, + 'mysqld_safe' => { + 'nice' => '0', + 'log_error' => $mysql::params::log_error, + 'socket' => $mysql::params::socket, + }, + 'mysqld' => { + 'basedir' => $mysql::params::basedir, + 'bind_address' => '127.0.0.1', + 'datadir' => $mysql::params::datadir, + 'expire_logs_days' => '10', + 'key_buffer' => '16M', + 'log_error' => $mysql::params::log_error, + 'max_allowed_packet' => '16M', + 'max_binlog_size' => '100M', + 'max_connections' => '151', + 'myisam_recover' => 'BACKUP', + 'pid_file' => $mysql::params::pidfile, + 'port' => '3306', + 'query_cache_limit' => '1M', + 'query_cache_size' => '16M', + 'skip-external-locking' => true, + 'socket' => $mysql::params::socket, + 'ssl' => false, + 'ssl-ca' => $mysql::params::ssl_ca, + 'ssl-cert' => $mysql::params::ssl_cert, + 'ssl-key' => $mysql::params::ssl_key, + 'thread_cache_size' => '8', + 'thread_stack' => '256K', + 'tmpdir' => $mysql::params::tmpdir, + 'user' => 'mysql', + }, + 'mysqldump' => { + 'max_allowed_packets' => '16M', + 'quick' => true, + 'quote-names' => true, + }, + 'isamchk' => { + 'key_buffer' => '16M', + }, + } + } diff --git a/manifests/server.pp b/manifests/server.pp index 1098395..94bd902 100644 --- a/manifests/server.pp +++ b/manifests/server.pp @@ -4,16 +4,23 @@ class mysql::server ( $enabled = undef, $manage_service = undef, # + $config_file = $mysql::params::config_file, + $manage_config_file = $mysql::params::manage_config_file, $old_root_password = $mysql::params::old_root_password, + $old_root_password = $mysql::params::old_root_password, + $override_options = {}, $package_ensure = $mysql::params::server_package_ensure, $package_name = $mysql::params::server_package_name, + $purge_conf_dir = $mysql::params::purge_conf_dir, $remove_default_accounts = false, + $restart = $mysql::params::restart, + $root_group = $mysql::params::root_group, $root_password = $mysql::params::root_password, $service_enabled = $mysql::params::server_service_enabled, $service_manage = $mysql::params::server_service_manage, $service_name = $mysql::params::server_service_name, $service_provider = $mysql::params::server_service_provider -) inherits mysql::globals { +) inherits mysql::params { # Deprecated parameters. if $enabled { @@ -29,6 +36,9 @@ class mysql::server ( $real_service_manage = $service_manage } + # Create a merged together set of options. Rightmost hashes win over left. + $options = merge($mysql::params::default_options, $override_options) + Class['mysql::server::root_password'] -> Mysql::Db <| |> include '::mysql::server::install' diff --git a/manifests/server/config.pp b/manifests/server/config.pp index 8ad5ac0..3e85cfa 100644 --- a/manifests/server/config.pp +++ b/manifests/server/config.pp @@ -1,9 +1,11 @@ # See README.me for options. class mysql::server::config { + $options = $mysql::server::options + File { owner => 'root', - group => $mysql::globals::root_group, + group => $mysql::server::root_group, mode => '0400', notify => Class['mysql::server::service'], } @@ -16,12 +18,12 @@ class mysql::server::config { file { '/etc/mysql/conf.d': ensure => directory, mode => '0755', - recurse => $mysql::globals::purge_conf_dir, - purge => $mysql::globals::purge_conf_dir, + recurse => $mysql::server::purge_conf_dir, + purge => $mysql::server::purge_conf_dir, } - if $mysql::globals::manage_config_file { - file { $mysql::globals::config_file: + if $mysql::server::manage_config_file { + file { $mysql::server::config_file: content => template('mysql/my.cnf.erb'), mode => '0644', } diff --git a/manifests/server/root_password.pp b/manifests/server/root_password.pp index 217a736..994b869 100644 --- a/manifests/server/root_password.pp +++ b/manifests/server/root_password.pp @@ -1,7 +1,7 @@ # class mysql::server::root_password { - $options = $mysql::globals::options + $options = $mysql::server::options # manage root password if it is set if $mysql::server::root_password != 'UNSET' { diff --git a/spec/system/mysql_backup_spec.rb b/spec/system/mysql_backup_spec.rb index bab3fa1..f071c7a 100644 --- a/spec/system/mysql_backup_spec.rb +++ b/spec/system/mysql_backup_spec.rb @@ -3,8 +3,7 @@ require 'spec_helper_system' describe 'mysql::server::backup class' do context 'should work with no errors' do pp = <<-EOS - class { 'mysql::globals': override_options => { 'root_password' => 'password' } } - class { 'mysql::server': } + class { 'mysql::server': override_options => { 'root_password' => 'password' } } mysql::db { 'backup1': user => 'backup', password => 'secret', @@ -43,8 +42,7 @@ describe 'mysql::server::backup class' do context 'should create one file per database' do pp = <<-EOS - class { 'mysql::globals': override_options => { 'root_password' => 'password' } } - class { 'mysql::server': } + class { 'mysql::server': override_options => { 'root_password' => 'password' } } mysql::db { 'backup1': user => 'backup', password => 'secret', diff --git a/spec/system/mysql_db_spec.rb b/spec/system/mysql_db_spec.rb index 2e7ffa1..49299e1 100644 --- a/spec/system/mysql_db_spec.rb +++ b/spec/system/mysql_db_spec.rb @@ -5,8 +5,7 @@ describe 'mysql::db define' do # Using puppet_apply as a helper it 'should work with no errors' do pp = <<-EOS - class { 'mysql::globals': override_options => { 'root_password' => 'password' } } - class { 'mysql::server': } + class { 'mysql::server': override_options => { 'root_password' => 'password' } } mysql::db { 'spec1': user => 'root1', password => 'password', @@ -32,8 +31,7 @@ describe 'mysql::db define' do # Using puppet_apply as a helper it 'should work with no errors' do pp = <<-EOS - class { 'mysql::globals': override_options => { 'root_password' => 'password' } } - class { 'mysql::server': } + class { 'mysql::server': override_options => { 'root_password' => 'password' } } file { '/tmp/spec.sql': ensure => file, content => 'CREATE TABLE table1 (id int);',