Skip to content

parameterize mysqld config_dir #492

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 1 commit 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
5 changes: 5 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -169,6 +169,11 @@ You can just make an entry like `thing => true`, `thing => value`, or `thing =>

The location of the MySQL configuration file.

#####`config_dir`

The location of the MySQL configuration dir. Note: This is not the conf.d
directory!

#####`manage_config_file`

Whether the MySQL configuration file should be managed.
Expand Down
1 change: 1 addition & 0 deletions manifests/params.pp
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
$manage_config_file = true
$old_root_password = ''
$purge_conf_dir = false
$config_dir = '/etc/mysql'
$restart = false
$root_password = 'UNSET'
$server_package_ensure = 'present'
Expand Down
1 change: 1 addition & 0 deletions manifests/server.pp
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
# Class: mysql::server: See README.md for documentation.
class mysql::server (
$config_file = $mysql::params::config_file,
$config_dir = $mysql::params::config_dir,
$manage_config_file = $mysql::params::manage_config_file,
$old_root_password = $mysql::params::old_root_password,
$override_options = {},
Expand Down
4 changes: 2 additions & 2 deletions manifests/server/config.pp
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,12 @@
mode => '0400',
}

file { '/etc/mysql':
file { $mysql::server::config_dir:
Copy link
Contributor

Choose a reason for hiding this comment

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

This patch should not be provided at all. It's in package.

ensure => directory,
mode => '0755',
}

file { '/etc/mysql/conf.d':
file { "${mysql::server::config_dir}/conf.d":
Copy link
Contributor

Choose a reason for hiding this comment

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

This one should be parametrized.

ensure => directory,
mode => '0755',
recurse => $mysql::server::purge_conf_dir,
Expand Down
30 changes: 30 additions & 0 deletions spec/acceptance/mysql_server_config_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,36 @@ class { 'mysql::server':
end
end

describe 'config dir location', :unless => UNSUPPORTED_PLATFORMS.include?(fact('operatingsystem')) do
it 'creates the config dir elsewhere' do
pp = <<-EOS
class { 'mysql::server':
config_dir => '/etc/alternativedir',
}
EOS
apply_manifest(pp, :catch_failures => true)
end

describe file('/etc/alternativedir') do
it { should be_directory }
end
end

describe 'config dir location', :unless => UNSUPPORTED_PLATFORMS.include?(fact('operatingsystem')) do
it 'creates the config dir elsewhere' do
pp = <<-EOS
class { 'mysql::server':
config_dir => '/etc/alternativedir',
}
EOS
apply_manifest(pp, :catch_failures => true)
end

describe file('/etc/alternativedir') do
it { should be_directory }
end
end

describe 'manage_config_file' do
it 'wont reset the location of my.cnf' do
pp = <<-EOS
Expand Down
21 changes: 21 additions & 0 deletions spec/classes/mysql_server_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,27 @@
end
end

context 'mysql::server::config alternative conf dir' do
let(:params){{ :config_dir => '/etc/mysql-alternative' }}
it do
should contain_file('/etc/mysql-alternative').with({
:ensure => :directory,
:mode => '0755',
})
end
it do
should contain_file('/etc/mysql-alternative/conf.d').with({
:ensure => :directory,
:mode => '0755',
})
end
it do
should contain_file('/etc/mysql-alternative/my.cnf').with_content(
Copy link
Contributor

Choose a reason for hiding this comment

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

This file location is the value of $config_file which in this case should be /etc/my.cnf since the osfamily fact is set to RedHat.

%r{^!includedir /etc/mysql-alternative/conf.d/$}
)
end
end

context 'mysql::server::config' do
it do
should contain_file('/etc/mysql').with({
Expand Down
2 changes: 1 addition & 1 deletion templates/my.cnf.erb
Original file line number Diff line number Diff line change
Expand Up @@ -17,4 +17,4 @@
<% end %>
<% end -%>

!includedir /etc/mysql/conf.d/
!includedir <%= scope.lookupvar('mysql::server::config_dir') %>/conf.d