Skip to content

Parametrize !includedir #509

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

Merged
merged 1 commit into from
Jul 23, 2014
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
7 changes: 5 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ replicate-do-db = base2
###Custom configuration

To add custom MySQL configuration, drop additional files into
`/etc/mysql/conf.d/`. Dropping files into conf.d allows you to override settings or add additional ones, which is helpful if you choose not to use `override_options` in `mysql::server`. The conf.d location is hardcoded into the my.cnf template file.
`includedir`. Dropping files into `includedir` allows you to override settings or add additional ones, which is helpful if you choose not to use `override_options` in `mysql::server`. The `includedir` location is by default set to /etc/mysql/conf.d.

##Reference

Expand Down Expand Up @@ -173,9 +173,12 @@ The location of the MySQL configuration file.

Whether the MySQL configuration file should be managed.

#####`includedir`
The location of !includedir for custom configuration overrides.

#####`purge_conf_dir`

Whether the conf.d directory should be purged.
Whether the `includedir` directory should be purged.

#####`restart`

Expand Down
9 changes: 8 additions & 1 deletion manifests/params.pp
Original file line number Diff line number Diff line change
Expand Up @@ -54,14 +54,17 @@
$server_package_name = 'mariadb-server'
$server_service_name = 'mariadb'
$log_error = '/var/log/mariadb/mariadb.log'
$config_file = '/etc/my.cnf'
$config_file = '/etc/my.cnf.d/server.cnf'
Copy link
Contributor

Choose a reason for hiding this comment

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

Is this okay? Will this break anything ever? :)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

yum provides /etc/my.cnf and check it's content, we just make sure puppet by default won't touch it

# mariadb package by default has !includedir set in my.cnf to /etc/my.cnf.d
$includedir = undef
$pidfile = '/var/run/mariadb/mariadb.pid'
} else {
$client_package_name = 'mysql'
$server_package_name = 'mysql-server'
$server_service_name = 'mysqld'
$log_error = '/var/log/mysqld.log'
$config_file = '/etc/my.cnf'
$includedir = '/etc/my.cnf.d'
$pidfile = '/var/run/mysqld/mysqld.pid'
}

Expand Down Expand Up @@ -94,6 +97,7 @@
}
$basedir = '/usr'
$config_file = '/etc/my.cnf'
$includedir = '/etc/my.cnf.d'
$datadir = '/var/lib/mysql'
$log_error = $::operatingsystem ? {
/OpenSuSE/ => '/var/log/mysql/mysqld.log',
Expand Down Expand Up @@ -132,6 +136,7 @@

$basedir = '/usr'
$config_file = '/etc/mysql/my.cnf'
$includedir = '/etc/mysql/conf.d'
$datadir = '/var/lib/mysql'
$log_error = '/var/log/mysql/error.log'
$pidfile = '/var/run/mysqld/mysqld.pid'
Expand Down Expand Up @@ -160,6 +165,7 @@
$server_package_name = 'databases/mysql55-server'
$basedir = '/usr/local'
$config_file = '/var/db/mysql/my.cnf'
$includedir = '/var/db/mysql/my.cnf.d'
$datadir = '/var/db/mysql'
$log_error = "/var/db/mysql/${::hostname}.err"
$pidfile = '/var/db/mysql/mysql.pid'
Expand Down Expand Up @@ -188,6 +194,7 @@
$server_package_name = 'mysql-server'
$basedir = '/usr'
$config_file = '/etc/my.cnf'
$includedir = '/etc/my.cnf.d'
$datadir = '/var/lib/mysql'
$log_error = '/var/log/mysqld.log'
$pidfile = '/var/run/mysqld/mysqld.pid'
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,
$includedir = $mysql::params::includedir,
$manage_config_file = $mysql::params::manage_config_file,
$old_root_password = $mysql::params::old_root_password,
$override_options = {},
Expand Down
18 changes: 8 additions & 10 deletions manifests/server/config.pp
Original file line number Diff line number Diff line change
Expand Up @@ -2,23 +2,21 @@
class mysql::server::config {

$options = $mysql::server::options
$includedir = $mysql::server::includedir

File {
owner => 'root',
group => $mysql::server::root_group,
mode => '0400',
}

file { '/etc/mysql':
ensure => directory,
mode => '0755',
}

file { '/etc/mysql/conf.d':
ensure => directory,
mode => '0755',
recurse => $mysql::server::purge_conf_dir,
purge => $mysql::server::purge_conf_dir,
if $includedir and $includedir != '' {
file { "$mysql::server::includedir":
ensure => directory,
mode => '0755',
recurse => $mysql::server::purge_conf_dir,
purge => $mysql::server::purge_conf_dir,
}
}

if $mysql::server::manage_config_file {
Expand Down
40 changes: 40 additions & 0 deletions spec/acceptance/mysql_server_config_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,46 @@ class { 'mysql::server':
end
end

describe 'includedir location', :unless => UNSUPPORTED_PLATFORMS.include?(fact('operatingsystem')) do
it 'creates the file elsewhere' do
pp = <<-EOS
class { 'mysql::server':
includedir => '/etc/my.cnf.d',
config_file => '/etc/testmy.cnf',
}
EOS
# Make sure this doesn't exist so we can test if puppet
# readded it. It may not exist in the first place on
# some platforms.
shell('rmdir /etc/my.cnf.d', :acceptable_exit_codes => [0,1,2])
apply_manifest(pp, :catch_failures => true)
end

describe file('/etc/my.cnf.d') do
it { should be_directory }
end

describe file('/etc/testmy.cnf') do
it { sould contain "!includedir /etc/my.cnf.d" }
end
end

describe 'no includedir location', :unless => UNSUPPORTED_PLATFORMS.include?(fact('operatingsystem')) do
it 'creates the file elsewhere' do
pp = <<-EOS
class { 'mysql::server':
includedir => '',
config_file => '/etc/testmy.cnf',
}
EOS
apply_manifest(pp, :catch_failures => true)
end

describe file('/etc/testmy.cnf') do
it { should_not contain "includedir" }
end
end

describe 'resets', :unless => UNSUPPORTED_PLATFORMS.include?(fact('operatingsystem')) do
it 'cleans up' do
pp = <<-EOS
Expand Down
50 changes: 35 additions & 15 deletions spec/classes/mysql_server_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -76,24 +76,44 @@
end

context 'mysql::server::config' do
it do
should contain_file('/etc/mysql').with({
:ensure => :directory,
:mode => '0755',
})
end
context 'with includedir' do
let(:params) {{ :includedir => '/etc/my.cnf.d' }}
it do
should contain_file('/etc/my.cnf.d').with({
:ensure => :directory,
:mode => '0755',
})
end

it do
should contain_file('/etc/mysql/conf.d').with({
:ensure => :directory,
:mode => '0755',
})
it do
should contain_file('/etc/my.cnf').with({
:mode => '0644',
})
end

it do
should contain_file('/etc/my.cnf').with_content(/!includedir/)
end
end

it do
should contain_file('/etc/my.cnf').with({
:mode => '0644',
})
context 'without includedir' do
let(:params) {{ :includedir => '' }}
it do
should_not contain_file('/etc/my.cnf.d').with({
:ensure => :directory,
:mode => '0755',
})
end

it do
should contain_file('/etc/my.cnf').with({
:mode => '0644',
})
end

it do
should contain_file('/etc/my.cnf').without_content(/!includedir/)
end
end
end

Expand Down
4 changes: 3 additions & 1 deletion templates/my.cnf.erb
Original file line number Diff line number Diff line change
Expand Up @@ -17,4 +17,6 @@
<% end %>
<% end -%>

!includedir /etc/mysql/conf.d/
<% if @includedir and @includedir != '' %>
!includedir <%= @includedir %>
<% end %>