Skip to content
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

Added support for RHSCL mysql versions and support for .mylogin.cnf for MySQL 5.6.6+ #1061

Merged
merged 1 commit into from
Nov 9, 2018
Merged
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
111 changes: 111 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,8 @@ If you set the sql parameter to a file when creating a database, the file is imp

For large sql files, increase the `import_timeout` parameter, which defaults to 300 seconds.

If you have installed the mysql client in a non standard bin/sbin path you can set this with `mysql_exec_path` .

```puppet
mysql::db { 'mydb':
user => 'myuser',
Expand All @@ -136,6 +138,7 @@ mysql::db { 'mydb':
sql => '/path/to/sqlfile.gz',
import_cat_cmd => 'zcat',
import_timeout => 900,
mysql_exec_path => '/opt/rh/rh-myql57/root/bin'
}
```

Expand Down Expand Up @@ -386,6 +389,114 @@ mysql::server::db:
### Install Plugins

Plugins can be installed by using the `mysql_plugin` defined type. See `examples/mysql_plugin.pp` for futher examples.
## Reference

### Classes

#### Public classes

* [`mysql::server`](#mysqlserver): Installs and configures MySQL.
* [`mysql::server::monitor`](#mysqlservermonitor): Sets up a monitoring user.
* [`mysql::server::mysqltuner`](#mysqlservermysqltuner): Installs MySQL tuner script.
* [`mysql::server::backup`](#mysqlserverbackup): Sets up MySQL backups via cron.
* [`mysql::bindings`](#mysqlbindings): Installs various MySQL language bindings.
* [`mysql::client`](#mysqlclient): Installs MySQL client (for non-servers).

#### Private classes

* `mysql::server::install`: Installs packages.
* `mysql::server::installdb`: Implements setup of mysqld data directory (e.g. /var/lib/mysql)
* `mysql::server::config`: Configures MYSQL.
* `mysql::server::service`: Manages service.
* `mysql::server::account_security`: Deletes default MySQL accounts.
* `mysql::server::root_password`: Sets MySQL root password.
* `mysql::server::providers`: Creates users, grants, and databases.
* `mysql::bindings::client_dev`: Installs MySQL client development package.
* `mysql::bindings::daemon_dev`: Installs MySQL daemon development package.
* `mysql::bindings::java`: Installs Java bindings.
* `mysql::bindings::perl`: Installs Perl bindings.
* `mysql::bindings::php`: Installs PHP bindings.
* `mysql::bindings::python`: Installs Python bindings.
* `mysql::bindings::ruby`: Installs Ruby bindings.
* `mysql::client::install`: Installs MySQL client.
* `mysql::backup::mysqldump`: Implements mysqldump backups.
* `mysql::backup::mysqlbackup`: Implements backups with Oracle MySQL Enterprise Backup.
* `mysql::backup::xtrabackup`: Implements backups with XtraBackup from Percona.

### Parameters

#### mysql::server

##### `create_root_user`

Whether root user should be created.

Valid values are `true`, `false`.

Defaults to `true`.

This is useful for a cluster setup with Galera. The root user has to be created only once. You can set this parameter true on one node and set it to false on the remaining nodes.

##### `create_root_my_cnf`

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.

##### `root_password`

The MySQL root password. Puppet attempts to set the root password and update `/root/.my.cnf` with it.

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.

##### `old_root_password`

This parameter no longer does anything. It exists only for backwards compatibility. See the `root_password` parameter above for details on changing the root password.

##### `create_root_login_file`

Whether to create `/root/.mylogin.cnf` when using mysql 5.6.6+.

Valid values are `true`, `false`.

Defaults to `false`.

`create_root_login_file` will put a copy of your existing `.mylogin.cnf` in the `/root/.mylogin.cnf` location.

When set to 'true', this option also requires the `login_file` option.

The `login_file` option is required when set to true.

#### `login_file`

Whether to put the `/root/.mylogin.cnf` in place.

You need to create the `.mylogin.cnf` file with `mysql_config_editor`, this tool comes with mysql 5.6.6+.

The created .mylogin.cnf needs to be put under files in your module, see example below on how to use this.

When the `/root/.mylogin.cnf` exists the environment variable `MYSQL_TEST_LOGIN_FILE` will be set.

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

```puppet
class { '::mysql::server':
root_password => 'password',
create_root_my_cnf => false,
create_root_login_file => true,
login_file => "puppet:///modules/${module_name}/mylogin.cnf",
}
```

##### `override_options`

Specifies override options to pass into MySQL. Structured like a hash in the my.cnf file:

```puppet
class { 'mysql::server':
Expand Down
37 changes: 35 additions & 2 deletions lib/puppet/provider/mysql.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,29 @@ class Puppet::Provider::Mysql < Puppet::Provider

# Make sure we find mysql commands on CentOS and FreeBSD
ENV['PATH'] = ENV['PATH'] + ':/usr/libexec:/usr/local/libexec:/usr/local/bin'
ENV['LD_LIBRARY_PATH'] = [
ENV['LD_LIBRARY_PATH'],
'/usr/lib',
'/usr/lib64',
'/opt/rh/rh-mysql56/root/usr/lib',
'/opt/rh/rh-mysql56/root/usr/lib64',
'/opt/rh/rh-mysql57/root/usr/lib',
'/opt/rh/rh-mysql57/root/usr/lib64',
'/opt/rh/rh-mariadb100/root/usr/lib',
'/opt/rh/rh-mariadb100/root/usr/lib64',
'/opt/rh/rh-mariadb101/root/usr/lib',
'/opt/rh/rh-mariadb101/root/usr/lib64',
'/opt/rh/mysql55/root/usr/lib',
'/opt/rh/mysql55/root/usr/lib64',
'/opt/rh/mariadb55/root/usr/lib',
'/opt/rh/mariadb55/root/usr/lib64',
'/usr/mysql/5.5/lib',
'/usr/mysql/5.5/lib64',
'/usr/mysql/5.6/lib',
'/usr/mysql/5.6/lib64',
'/usr/mysql/5.7/lib',
'/usr/mysql/5.7/lib64',
].join(':')

# rubocop:disable Style/HashSyntax
commands :mysql_raw => 'mysql'
Expand Down Expand Up @@ -64,9 +87,19 @@ def defaults_file

def self.mysql_caller(text_of_sql, type)
if type.eql? 'system'
mysql_raw([defaults_file, system_database, '-e', text_of_sql].flatten.compact)
if File.file?("#{Facter.value(:root_home)}/.mylogin.cnf")
ENV['MYSQL_TEST_LOGIN_FILE'] = "#{Facter.value(:root_home)}/.mylogin.cnf"
mysql_raw(['--host=', system_database, '-e', text_of_sql].flatten.compact)
else
mysql_raw([defaults_file, '--host=', system_database, '-e', text_of_sql].flatten.compact)
end
elsif type.eql? 'regular'
mysql_raw([defaults_file, '-NBe', text_of_sql].flatten.compact)
if File.file?("#{Facter.value(:root_home)}/.mylogin.cnf")
ENV['MYSQL_TEST_LOGIN_FILE'] = "#{Facter.value(:root_home)}/.mylogin.cnf"
mysql_raw(['-NBe', text_of_sql].flatten.compact)
else
mysql_raw([defaults_file, '-NBe', text_of_sql].flatten.compact)
end
else
raise Puppet::Error, _("#mysql_caller: Unrecognised type '%{type}'" % { type: type })
end
Expand Down
3 changes: 2 additions & 1 deletion manifests/db.pp
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@
Enum['absent', 'present'] $ensure = 'present',
$import_timeout = 300,
$import_cat_cmd = 'cat',
$mysql_exec_path = $mysql::params::exec_path,
DJMuggs marked this conversation as resolved.
Show resolved Hide resolved
) {

$table = "${dbname}.*"
Expand Down Expand Up @@ -98,7 +99,7 @@
logoutput => true,
environment => "HOME=${::root_home}",
refreshonly => $refresh,
path => '/bin:/sbin:/usr/bin:/usr/sbin:/usr/local/bin',
path => "/bin:/sbin:/usr/bin:/usr/sbin:/usr/local/bin:${mysql_exec_path}",
require => Mysql_grant["${user}@${host}/${table}"],
subscribe => Mysql_database[$dbname],
timeout => $import_timeout,
Expand Down
3 changes: 3 additions & 0 deletions manifests/params.pp
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,9 @@
$client_package_manage = true
$create_root_user = true
$create_root_my_cnf = true
$create_root_login_file = false
$login_file = undef
$exec_path = ''
# mysql::bindings
$bindings_enable = false
$java_package_ensure = 'present'
Expand Down
2 changes: 2 additions & 0 deletions manifests/server.pp
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,8 @@
$service_provider = $mysql::params::server_service_provider,
$create_root_user = $mysql::params::create_root_user,
$create_root_my_cnf = $mysql::params::create_root_my_cnf,
$create_root_login_file = $mysql::params::create_root_login_file,
$login_file = $mysql::params::login_file,
Copy link
Contributor

Choose a reason for hiding this comment

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

What is the expected workflow of passing a login file? Why is it using the source parameter instead of content? Where does it come from?

Copy link
Author

Choose a reason for hiding this comment

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

You need to create the login file first with mysql_config_editor, this creates an encrypted file.
And because the tool uses interactive prompt for the password, it's not possible to create during a puppet run.
So that's why you need to source this instead of using content.

https://dev.mysql.com/doc/refman/5.6/en/mysql-config-editor.html

$users = {},
$grants = {},
$databases = {},
Expand Down
8 changes: 8 additions & 0 deletions manifests/server/root_password.pp
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@

$options = $mysql::server::options
$secret_file = $mysql::server::install_secret_file
$login_file = $mysql::server::login_file

# New installations of MySQL will configure a default random password for the root user
# with an expiration. No actions can be performed until this password is changed. The
Expand Down Expand Up @@ -47,4 +48,11 @@
}
}

if $mysql::server::create_root_login_file == true and $mysql::server::root_password != 'UNSET' {
file { "${::root_home}/.mylogin.cnf":
source => $login_file,
owner => 'root',
mode => '0600',
}
}
}
5 changes: 3 additions & 2 deletions spec/defines/mysql_db_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,9 @@
let(:title) { 'test_db' }

let(:params) do
{ 'user' => 'testuser',
'password' => 'testpass' }
{ 'user' => 'testuser',
'password' => 'testpass',
'mysql_exec_path' => '' }
end

it 'does not notify the import sql exec if no sql script was provided' do
Expand Down