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

Add managed_dirs parameter #1305

Merged
merged 5 commits into from Jun 23, 2020
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
9 changes: 9 additions & 0 deletions REFERENCE.md
Expand Up @@ -455,6 +455,15 @@ Whether the MySQL configuration file should be managed. Valid values are `true`,

Default value: $mysql::params::manage_config_file

##### `managed_dirs`

Data type: `Any`

Manage MySQL system directories which described in the section `[mysqld]` of the configuration file
`my.cnf`

Default value: `$mysql::params::managed_dirs`

##### `options`

Data type: `Mysql::Options`
Expand Down
1 change: 1 addition & 0 deletions manifests/server.pp
Expand Up @@ -88,6 +88,7 @@
$remove_default_accounts = false,
$restart = $mysql::params::restart,
$root_group = $mysql::params::root_group,
$managed_dirs = $mysql::params::managed_dirs,
$mysql_group = $mysql::params::mysql_group,
$mycnf_owner = $mysql::params::mycnf_owner,
$mycnf_group = $mysql::params::mycnf_group,
Expand Down
29 changes: 17 additions & 12 deletions manifests/server/config.pp
Expand Up @@ -36,21 +36,26 @@
}

#Debian: Creating world readable directories before installing.
if $managed_dirs {
$managed_dirs.each | $entry | {
$dir = $options['mysqld']["${entry}"]
if ( $dir and $dir != '/usr' and $dir != '/tmp' ) {
exec {"${entry}-managed_dir-mkdir":
command => "/bin/mkdir -p ${dir}",
unless => "/usr/bin/dpkg -s ${mysql::server::package_name}",
notify => Exec["${entry}-managed_dir-chmod"],
}
exec {"${entry}-managed_dir-chmod":
command => "/bin/chmod 777 ${dir}",
refreshonly => true,
case $::operatingsystem {
sheenaajay marked this conversation as resolved.
Show resolved Hide resolved
'Debian': {
if $managed_dirs {
$managed_dirs.each | $entry | {
$dir = $options['mysqld']["${entry}"]
if ( $dir and $dir != '/usr' and $dir != '/tmp' ) {
exec {"${entry}-managed_dir-mkdir":
command => "/bin/mkdir -p ${dir}",
unless => "/usr/bin/dpkg -s ${mysql::server::package_name}",
notify => Exec["${entry}-managed_dir-chmod"],
}
exec {"${entry}-managed_dir-chmod":
command => "/bin/chmod 777 ${dir}",
refreshonly => true,
}
}
}
}
}
default: {}
}

if $mysql::server::manage_config_file {
Expand Down
44 changes: 44 additions & 0 deletions spec/acceptance/mysql_mariadb_spec.rb
@@ -0,0 +1,44 @@
require 'spec_helper_acceptance'

describe 'mysql server class', if: ((os[:family] == 'debian' && os[:release].to_i > 8) || (os[:family] == 'redhat' && os[:release].to_i > 6)) do
describe 'mariadb' do
let(:pp) do
<<-MANIFEST
$osname = $facts['os']['name'].downcase
yumrepo {'mariadb':
baseurl => "http://yum.mariadb.org/10.4/$osname${facts['os']['release']['major']}-aarch64/",
gpgkey => 'https://yum.mariadb.org/RPM-GPG-KEY-MariaDB',
descr => "MariaDB 10.4",
enabled => 1,
gpgcheck => 1,
}->
class { '::mysql::server':
require => Yumrepo['mariadb'],
package_name => 'mariadb-server',
service_name => 'mariadb',
root_password => 'strongpassword',
remove_default_accounts => true,
managed_dirs => ['/var/log','/var/run/mysql'],
override_options => {
mysqld => {
log-error => '/var/log/mariadb.log',
pid-file => '/var/run/mysql/mysqld.pid',
},
mysqld_safe => {
log-error => '/var/log/mariadb.log',
},
},
}
MANIFEST
end

it 'apply manifest' do
apply_manifest(pp)
end
it 'mariadb connection' do
result = run_shell('mysql --user="root" --password="strongpassword" -e "status"')
expect(result.stdout).to match(%r{MariaDB})
expect(result.stderr).to be_empty
end
end
end