Skip to content

Commit 95611ae

Browse files
committed
Add possibility to override Mysql implementation.
Signed-off-by: Christophe Vanlancker <christophe.vanlancker@inuits.eu>
1 parent 8b36568 commit 95611ae

File tree

2 files changed

+50
-31
lines changed

2 files changed

+50
-31
lines changed

README.md

Lines changed: 29 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
* [Customizing Server Options](#customizing-server-options)
1111
* [Creating a Database](#creating-a-database)
1212
* [Custom Configuration](#custom-configuration)
13+
* [Overriding Mysql Implementation](#overriding-mysql-implementation)
1314
5. [Reference - An under-the-hood peek at what the module is doing and how](#reference)
1415
6. [Limitations - OS compatibility, etc.](#limitations)
1516
7. [Development - Guide for contributing to the module](#development)
@@ -25,7 +26,7 @@ The MySQL module manages both the installation and configuration of MySQL, as we
2526
### Beginning with MySQL
2627

2728
If you want a server installed with the default options you can run
28-
`include '::mysql::server'`.
29+
`include '::mysql::server'`.
2930

3031
If you need to customize options, such as the root
3132
password or `/etc/my.cnf` settings, then you must also pass in an override hash:
@@ -63,7 +64,7 @@ For items that you would traditionally represent as
6364
thing = X
6465
~~~
6566

66-
you can make an entry like `thing => true`, `thing => value`, or `thing => "` in the hash. Alternatively, you can pass an array, as `thing => ['value', 'value2']`, or list each `thing => value` separately on separate lines.
67+
you can make an entry like `thing => true`, `thing => value`, or `thing => "` in the hash. Alternatively, you can pass an array, as `thing => ['value', 'value2']`, or list each `thing => value` separately on separate lines.
6768

6869
MySQL doesn't care if 'thing' is alone or set to a value; it happily accepts both. To keep an option out of the my.cnf file --- e.g., when using `override_options` to revert to a default value --- you can pass `thing => undef`.
6970

@@ -152,6 +153,18 @@ server address and credentials. For example:
152153
When working with a remote server, do *not* use the
153154
`mysql::server` class in your Puppet manifests.
154155

156+
### Overriding Mysql Implementation
157+
158+
Depending on the distribution a certain assumption is being made to which flavour of Mysql is to be used by default (Oracle Mysql, MariaDB, ... ).
159+
160+
This can be overriden by specifing the provider_override option to the mysql::params class.
161+
162+
~~~
163+
class { 'mysql::params':
164+
provider_override => 'mysql',
165+
}
166+
~~~
167+
155168
## Reference
156169

157170
### Classes
@@ -209,7 +222,7 @@ The MySQL root password. Puppet attempts to set the root password and update `/r
209222

210223
This is required if `create_root_user` or `create_root_my_cnf` are 'true'. If `root_password` is 'UNSET', then `create_root_user` and `create_root_my_cnf` are assumed to be false --- that is, the MySQL root user and `/root/.my.cnf` are not created.
211224

212-
Password changes are supported; however, the old password must be set in `/root/.my.cnf`. Effectively, Puppet uses the old password, configured in `/root/my.cnf`, to set the new password in MySQL, and then updates `/root/.my.cnf` with the new password.
225+
Password changes are supported; however, the old password must be set in `/root/.my.cnf`. Effectively, Puppet uses the old password, configured in `/root/my.cnf`, to set the new password in MySQL, and then updates `/root/.my.cnf` with the new password.
213226

214227
##### `old_root_password`
215228

@@ -293,7 +306,7 @@ The provider to use to manage the service. For Ubuntu, defaults to 'upstart'; ot
293306

294307
##### `users`
295308

296-
Optional hash of users to create, which are passed to [mysql_user](#mysql_user).
309+
Optional hash of users to create, which are passed to [mysql_user](#mysql_user).
297310

298311
~~~
299312
users => {
@@ -310,7 +323,7 @@ users => {
310323

311324
##### `grants`
312325

313-
Optional hash of grants, which are passed to [mysql_grant](#mysql_grant).
326+
Optional hash of grants, which are passed to [mysql_grant](#mysql_grant).
314327

315328
~~~
316329
grants => {
@@ -434,7 +447,7 @@ The password to create for MySQL monitoring.
434447

435448
##### `mysql_monitor_hostname`
436449

437-
The hostname from which the monitoring user requests are allowed access.
450+
The hostname from which the monitoring user requests are allowed access.
438451

439452
#### mysql::server::mysqltuner
440453

@@ -489,11 +502,11 @@ Pass `install_options` array to managed package resources. You must pass the [ap
489502
##### `client_dev_package_ensure`
490503

491504
Whether the package should be present, absent, or a specific version. Valid values are 'present', 'absent', or 'x.y.z'. Only applies if `client_dev => true`.
492-
505+
493506
##### `client_dev_package_name`
494507

495508
The name of the client_dev package to install. Only applies if `client_dev => true`.
496-
509+
497510
##### `client_dev_package_provider`
498511

499512
The provider to use to install the client_dev package. Only applies if `client_dev => true`.
@@ -537,7 +550,7 @@ The provider to use to install the Perl package. Only applies if `perl_enable =>
537550
##### `php_package_ensure`
538551

539552
Whether the package should be present, absent, or a specific version. Valid values are 'present', 'absent', or 'x.y.z'. Only applies if `php_enable => true`.
540-
553+
541554
##### `php_package_name`
542555

543556
The name of the PHP package to install. Only applies if `php_enable => true`.
@@ -607,23 +620,23 @@ mysql_database { 'mysql':
607620
##### `user`
608621

609622
The user for the database you're creating.
610-
623+
611624
##### `password`
612625

613626
The password for $user for the database you're creating.
614627

615628
##### `dbname`
616629

617630
The name of the database to create. Defaults to $name.
618-
631+
619632
##### `charset`
620633

621634
The character set for the database. Defaults to 'utf8'.
622635

623636
##### `collate`
624637

625638
The collation for the database. Defaults to 'utf8_general_ci'.
626-
639+
627640
##### `host`
628641

629642
The host to use as part of user@host for grants. Defaults to 'localhost'.
@@ -639,10 +652,10 @@ The path to the sqlfile you want to execute. This can be single file specified a
639652
##### `enforce_sql`
640653

641654
Specify whether executing the sqlfiles should happen on every run. If set to 'false', sqlfiles only run once. Valid values are 'true', 'false'. Defaults to 'false'.
642-
655+
643656
##### `ensure`
644657

645-
Specify whether to create the database. Valid values are 'present', 'absent'. Defaults to 'present'.
658+
Specify whether to create the database. Valid values are 'present', 'absent'. Defaults to 'present'.
646659

647660
##### `import_timeout`
648661

@@ -668,7 +681,7 @@ The CHARACTER SET setting for the database. Defaults to ':utf8'.
668681

669682
##### `collate`
670683

671-
The COLLATE setting for the database. Defaults to ':utf8_general_ci'.
684+
The COLLATE setting for the database. Defaults to ':utf8_general_ci'.
672685

673686
#### mysql_user
674687

@@ -751,7 +764,7 @@ Whether the resource is present. Valid values are 'present', 'absent'. Defaults
751764

752765
##### `name`
753766

754-
Name to describe the grant. Must in a 'user/table' format.
767+
Name to describe the grant. Must in a 'user/table' format.
755768

756769
##### `privileges`
757770

manifests/params.pp

Lines changed: 21 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
# Private class: See README.md.
2-
class mysql::params {
2+
class mysql::params (
3+
$provider_override = undef,
4+
) {
35

46
$manage_config_file = true
57
$purge_conf_dir = false
@@ -34,24 +36,28 @@
3436

3537
case $::osfamily {
3638
'RedHat': {
37-
case $::operatingsystem {
38-
'Fedora': {
39-
if versioncmp($::operatingsystemrelease, '19') >= 0 or $::operatingsystemrelease == 'Rawhide' {
40-
$provider = 'mariadb'
41-
} else {
42-
$provider = 'mysql'
39+
if $provider_override == undef {
40+
case $::operatingsystem {
41+
'Fedora': {
42+
if versioncmp($::operatingsystemrelease, '19') >= 0 or $::operatingsystemrelease == 'Rawhide' {
43+
$provider = 'mariadb'
44+
} else {
45+
$provider = 'mysql'
46+
}
4347
}
44-
}
45-
/^(RedHat|CentOS|Scientific|OracleLinux)$/: {
46-
if versioncmp($::operatingsystemmajrelease, '7') >= 0 {
47-
$provider = 'mariadb'
48-
} else {
48+
/^(RedHat|CentOS|Scientific|OracleLinux)$/: {
49+
if versioncmp($::operatingsystemmajrelease, '7') >= 0 {
50+
$provider = 'mariadb'
51+
} else {
52+
$provider = 'mysql'
53+
}
54+
}
55+
default: {
4956
$provider = 'mysql'
5057
}
5158
}
52-
default: {
53-
$provider = 'mysql'
54-
}
59+
} else {
60+
$provider = $provider_override
5561
}
5662

5763
if $provider == 'mariadb' {

0 commit comments

Comments
 (0)