Skip to content

Commit 36f75fc

Browse files
committed
allow adapting permission mode of the MySQL configuration file
1 parent 07e0873 commit 36f75fc

File tree

4 files changed

+56
-4
lines changed

4 files changed

+56
-4
lines changed

manifests/params.pp

+1
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
class mysql::params {
77

88
$manage_config_file = true
9+
$config_file_mode = '0644'
910
$purge_conf_dir = false
1011
$restart = false
1112
$root_password = 'UNSET'

manifests/server.pp

+6-3
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@
1111
#
1212
# @param config_file
1313
# The location, as a path, of the MySQL configuration file.
14+
# @param config_file_mode
15+
# The MySQL configuration file's permissions mode.
1416
# @param includedir
1517
# The location, as a path, of !includedir for custom configuration overrides.
1618
# @param install_options
@@ -52,11 +54,11 @@
5254
# @param create_root_my_cnf
5355
# 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.
5456
# @param users
55-
# Optional hash of users to create, which are passed to [mysql_user](#mysql_user).
57+
# Optional hash of users to create, which are passed to [mysql_user](#mysql_user).
5658
# @param grants
57-
# Optional hash of grants, which are passed to [mysql_grant](#mysql_grant).
59+
# Optional hash of grants, which are passed to [mysql_grant](#mysql_grant).
5860
# @param databases
59-
# Optional hash of databases to create, which are passed to [mysql_database](#mysql_database).
61+
# Optional hash of databases to create, which are passed to [mysql_database](#mysql_database).
6062
# @param enabled
6163
# _Deprecated_
6264
# @param manage_service
@@ -66,6 +68,7 @@
6668
#
6769
class mysql::server (
6870
$config_file = $mysql::params::config_file,
71+
$config_file_mode = $mysql::params::config_file_mode,
6972
$includedir = $mysql::params::includedir,
7073
$install_options = undef,
7174
$install_secret_file = $mysql::params::install_secret_file,

manifests/server/config.pp

+1-1
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@
3737
file { 'mysql-config-file':
3838
path => $mysql::server::config_file,
3939
content => template('mysql/my.cnf.erb'),
40-
mode => '0644',
40+
mode => $mysql::server::config_file_mode,
4141
selinux_ignore_defaults => true,
4242
}
4343

spec/classes/mycnf_template_spec.rb

+48
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,54 @@
8080

8181
it { is_expected.to contain_file('mysql-config-file').without_content(%r{!includedir}) }
8282
end
83+
84+
context 'with file mode 0644' do
85+
let(:params) { { 'config_file_mode' => '0644' } }
86+
87+
it do
88+
is_expected.to contain_file('mysql-config-file').with(mode: '0644')
89+
end
90+
end
91+
92+
context 'with file mode 0664' do
93+
let(:params) { { 'config_file_mode' => '0664' } }
94+
95+
it do
96+
is_expected.to contain_file('mysql-config-file').with(mode: '0664')
97+
end
98+
end
99+
100+
context 'with file mode 0660' do
101+
let(:params) { { 'config_file_mode' => '0660' } }
102+
103+
it do
104+
is_expected.to contain_file('mysql-config-file').with(mode: '0660')
105+
end
106+
end
107+
108+
context 'with file mode 0641' do
109+
let(:params) { { 'config_file_mode' => '0641' } }
110+
111+
it do
112+
is_expected.to contain_file('mysql-config-file').with(mode: '0641')
113+
end
114+
end
115+
116+
context 'with file mode 0610' do
117+
let(:params) { { 'config_file_mode' => '0610' } }
118+
119+
it do
120+
is_expected.to contain_file('mysql-config-file').with(mode: '0610')
121+
end
122+
end
123+
124+
context 'with file 0600' do
125+
let(:params) { { 'config_file_mode' => '0600' } }
126+
127+
it do
128+
is_expected.to contain_file('mysql-config-file').with(mode: '0600')
129+
end
130+
end
83131
end
84132
end
85133
end

0 commit comments

Comments
 (0)