Skip to content

Add possibility to override Mysql implementation #757

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
45 changes: 29 additions & 16 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
* [Customizing Server Options](#customizing-server-options)
* [Creating a Database](#creating-a-database)
* [Custom Configuration](#custom-configuration)
* [Overriding Mysql Implementation](#overriding-mysql-implementation)
5. [Reference - An under-the-hood peek at what the module is doing and how](#reference)
6. [Limitations - OS compatibility, etc.](#limitations)
7. [Development - Guide for contributing to the module](#development)
Expand All @@ -25,7 +26,7 @@ The MySQL module manages both the installation and configuration of MySQL, as we
### Beginning with MySQL

If you want a server installed with the default options you can run
`include '::mysql::server'`.
`include '::mysql::server'`.

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

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.
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.

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`.

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

### Overriding Mysql Implementation

Depending on the distribution a certain assumption is being made to which flavour of Mysql is to be used by default (Oracle Mysql, MariaDB, ... ).

This can be overriden by specifing the provider_override option to the mysql::params class.

~~~
class { 'mysql::params':
provider_override => 'mysql',
}
~~~

## Reference

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

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.

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.
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.

##### `old_root_password`

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

##### `users`

Optional hash of users to create, which are passed to [mysql_user](#mysql_user).
Optional hash of users to create, which are passed to [mysql_user](#mysql_user).

~~~
users => {
Expand All @@ -310,7 +323,7 @@ users => {

##### `grants`

Optional hash of grants, which are passed to [mysql_grant](#mysql_grant).
Optional hash of grants, which are passed to [mysql_grant](#mysql_grant).

~~~
grants => {
Expand Down Expand Up @@ -434,7 +447,7 @@ The password to create for MySQL monitoring.

##### `mysql_monitor_hostname`

The hostname from which the monitoring user requests are allowed access.
The hostname from which the monitoring user requests are allowed access.

#### mysql::server::mysqltuner

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

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`.

##### `client_dev_package_name`

The name of the client_dev package to install. Only applies if `client_dev => true`.

##### `client_dev_package_provider`

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

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`.

##### `php_package_name`

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

The user for the database you're creating.

##### `password`

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

##### `dbname`

The name of the database to create. Defaults to $name.

##### `charset`

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

##### `collate`

The collation for the database. Defaults to 'utf8_general_ci'.

##### `host`

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

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'.

##### `ensure`

Specify whether to create the database. Valid values are 'present', 'absent'. Defaults to 'present'.
Specify whether to create the database. Valid values are 'present', 'absent'. Defaults to 'present'.

##### `import_timeout`

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

##### `collate`

The COLLATE setting for the database. Defaults to ':utf8_general_ci'.
The COLLATE setting for the database. Defaults to ':utf8_general_ci'.

#### mysql_user

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

##### `name`

Name to describe the grant. Must in a 'user/table' format.
Name to describe the grant. Must in a 'user/table' format.

##### `privileges`

Expand Down
42 changes: 27 additions & 15 deletions manifests/params.pp
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
# Private class: See README.md.
class mysql::params {
class mysql::params (
$provider_override = undef,
) {

$manage_config_file = true
$purge_conf_dir = false
Expand Down Expand Up @@ -31,27 +33,37 @@
$daemon_dev_package_ensure = 'present'
$daemon_dev_package_provider = undef

# Validate provider_override value
if $provider_override != undef {
if ! $provider_override =~ /^(mariadb|mysql)$/ {
fail('Invalid provider_override value passed. Only \'mariadb\' or \'mysql\' allowed.')
}
}

case $::osfamily {
'RedHat': {
case $::operatingsystem {
'Fedora': {
if versioncmp($::operatingsystemrelease, '19') >= 0 or $::operatingsystemrelease == 'Rawhide' {
$provider = 'mariadb'
} else {
$provider = 'mysql'
if $provider_override == undef {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would be more comfortable with this if the conditional handled the provider_override case first and do some validation.

if $provider_override != undef {
  if $provider_override =~ /^(mariadb|mysql)$/ {
    $provider = $provider_override
  } else {
    # maybe error due to failed validation of $provider_override?
  }
}

I'm hesitant in keeping this vague, because for example on Fedora 19+ the default provider would be mariadb, but if the override were improperly set to foo, then according to this codepath, the block at line 72 would continue the setup as if it were mysql.

case $::operatingsystem {
'Fedora': {
if versioncmp($::operatingsystemrelease, '19') >= 0 or $::operatingsystemrelease == 'Rawhide' {
$provider = 'mariadb'
} else {
$provider = 'mysql'
}
}
}
/^(RedHat|CentOS|Scientific|OracleLinux)$/: {
if versioncmp($::operatingsystemmajrelease, '7') >= 0 {
$provider = 'mariadb'
} else {
/^(RedHat|CentOS|Scientific|OracleLinux)$/: {
if versioncmp($::operatingsystemmajrelease, '7') >= 0 {
$provider = 'mariadb'
} else {
$provider = 'mysql'
}
}
default: {
$provider = 'mysql'
}
}
default: {
$provider = 'mysql'
}
} else {
$provider = $provider_override
}

if $provider == 'mariadb' {
Expand Down