Skip to content

Commit 7ac8328

Browse files
author
Maurice Meyer
committed
Enable module to not use default options
1 parent 09fc61c commit 7ac8328

File tree

9 files changed

+60
-15
lines changed

9 files changed

+60
-15
lines changed

README.md

+3
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,9 @@ replicate-do-db = base2
9191

9292
To implement version specific parameters, specify the version, such as [mysqld-5.5]. This allows one config for different versions of MySQL.
9393

94+
If you don’t want to use the default configuration, you can also supply your options to the `$options` parameter instead of `$override_options`.
95+
Please note that `$options` and `$override_options` are mutually exclusive, you can only use one of them.
96+
9497
### Create a database
9598

9699
To create a database with a user and some assigned privileges:

locales/puppetlabs-mysql.pot

+6
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,12 @@ msgid ""
7777
"future release."
7878
msgstr ""
7979

80+
#. ./manifests/server.pp:122
81+
msgid ""
82+
"You can\'t specify $options and $override_options simultaneously, see the "
83+
"README section \'Customize server options\'!"
84+
msgstr ""
85+
8086
#: ./lib/puppet/parser/functions/mysql_deepmerge.rb:22
8187
msgid ""
8288
"mysql_deepmerge(): wrong number of arguments (%{args_length}; must be at "

manifests/server.pp

+16-5
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,8 @@
1919
# Path to secret file containing temporary root password.
2020
# @param manage_config_file
2121
# Whether the MySQL configuration file should be managed. Valid values are `true`, `false`. Defaults to `true`.
22+
# @param options
23+
# A hash of options structured like the override_options, but not merged with the default options. Use this if you don’t want your options merged with the default options.
2224
# @param override_options
2325
# Specifies override options to pass into MySQL. Structured like a hash in the my.cnf file: See above for usage details.
2426
# @param package_ensure
@@ -52,11 +54,11 @@
5254
# @param create_root_my_cnf
5355
# Whether to create `/root/.my.cnf`. Valid values are `true`, `false`. Defaults to `true`. `create_root_my_cnf` allows creation of `/root/.my.cnf` independently of `create_root_user`. You can use this for a cluster setup with Galera where you want `/root/.my.cnf` to exist on all nodes.
5456
# @param users
55-
# Optional hash of users to create, which are passed to [mysql_user](#mysql_user).
57+
# Optional hash of users to create, which are passed to [mysql_user](#mysql_user).
5658
# @param grants
57-
# Optional hash of grants, which are passed to [mysql_grant](#mysql_grant).
59+
# Optional hash of grants, which are passed to [mysql_grant](#mysql_grant).
5860
# @param databases
59-
# Optional hash of databases to create, which are passed to [mysql_database](#mysql_database).
61+
# Optional hash of databases to create, which are passed to [mysql_database](#mysql_database).
6062
# @param enabled
6163
# _Deprecated_
6264
# @param manage_service
@@ -70,6 +72,7 @@
7072
$install_options = undef,
7173
$install_secret_file = $mysql::params::install_secret_file,
7274
$manage_config_file = $mysql::params::manage_config_file,
75+
$options = {},
7376
$override_options = {},
7477
$package_ensure = $mysql::params::server_package_ensure,
7578
$package_manage = $mysql::params::server_package_manage,
@@ -115,8 +118,16 @@
115118
warning(translate('The `old_root_password` attribute is no longer used and will be removed in a future release.'))
116119
}
117120

118-
# Create a merged together set of options. Rightmost hashes win over left.
119-
$options = mysql::normalise_and_deepmerge($mysql::params::default_options, $override_options)
121+
if ! empty($options) and ! empty($override_options) {
122+
fail(translate('You can\'t specify $options and $override_options simultaneously, see the README section \'Customize server options\'!'))
123+
}
124+
125+
# If override_options are set, create a merged together set of options. Rightmost hashes win over left.
126+
# If options are set, just use them.
127+
$_options = empty($options) ? {
128+
true => mysql::normalise_and_deepmerge($mysql::params::default_options, $override_options),
129+
false => $options,
130+
}
120131

121132
Class['mysql::server::root_password'] -> Mysql::Db <| |>
122133

manifests/server/binarylog.pp

+1-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
#
66
class mysql::server::binarylog {
77

8-
$options = $mysql::server::options
8+
$options = $mysql::server::_options
99
$includedir = $mysql::server::includedir
1010

1111
$logbin = pick($options['mysqld']['log-bin'], $options['mysqld']['log_bin'], false)

manifests/server/config.pp

+1-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
#
66
class mysql::server::config {
77

8-
$options = $mysql::server::options
8+
$options = $mysql::server::_options
99
$includedir = $mysql::server::includedir
1010

1111
File {

manifests/server/installdb.pp

+6-6
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,19 @@
1-
# @summary
1+
# @summary
22
# Builds initial databases on installation.
33
#
44
# @api private
55
#
66
class mysql::server::installdb {
7-
$options = $mysql::server::options
7+
$options = $mysql::server::_options
88

99
if $mysql::server::package_manage {
1010

1111
# Build the initial databases.
12-
$mysqluser = $mysql::server::options['mysqld']['user']
13-
$datadir = $mysql::server::options['mysqld']['datadir']
14-
$basedir = $mysql::server::options['mysqld']['basedir']
12+
$mysqluser = $mysql::server::_options['mysqld']['user']
13+
$datadir = $mysql::server::_options['mysqld']['datadir']
14+
$basedir = $mysql::server::_options['mysqld']['basedir']
1515
$config_file = $mysql::server::config_file
16-
$log_error = $mysql::server::options['mysqld']['log-error']
16+
$log_error = $mysql::server::_options['mysqld']['log-error']
1717

1818
if $mysql::server::manage_config_file and $config_file != $mysql::params::config_file {
1919
$_config_file=$config_file

manifests/server/root_password.pp

+1-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
#
66
class mysql::server::root_password {
77

8-
$options = $mysql::server::options
8+
$options = $mysql::server::_options
99
$secret_file = $mysql::server::install_secret_file
1010
$login_file = $mysql::server::login_file
1111

manifests/server/service.pp

+1-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
# @api private
55
#
66
class mysql::server::service {
7-
$options = $mysql::server::options
7+
$options = $mysql::server::_options
88

99
if $mysql::server::real_service_manage {
1010
if $mysql::server::real_service_enabled {

spec/classes/mysql_server_spec.rb

+25
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,31 @@
3434
it { is_expected.not_to contain_service('mysqld') }
3535
end
3636

37+
context 'configuration options' do
38+
context 'when specifying both $override_options and $options' do
39+
let(:params) do
40+
{
41+
override_options: { 'mysqld' => { 'datadir' => '/tmp' } },
42+
options: { 'mysqld' => { 'max_allowed_packet' => '12M' } },
43+
}
44+
end
45+
46+
it { is_expected.to compile.and_raise_error(%r{You can't specify \$options and \$override_options simultaneously, see the README section 'Customize server options'!}) }
47+
end
48+
49+
context 'when specifying $options' do
50+
let(:params) do
51+
{
52+
options: { 'mysqld' => { 'datadir' => '/tmp' } },
53+
}
54+
end
55+
56+
it { is_expected.to compile.with_all_deps }
57+
it { is_expected.to contain_mysql_datadir('/tmp') }
58+
it { is_expected.not_to contain_mysql_bind_addr('127.0.0.1') }
59+
end
60+
end
61+
3762
context 'mysql::server::install' do
3863
it 'contains the package by default' do
3964
is_expected.to contain_package('mysql-server').with(ensure: :present)

0 commit comments

Comments
 (0)