File tree 4 files changed +34
-0
lines changed
4 files changed +34
-0
lines changed Original file line number Diff line number Diff line change 5
5
$purge_conf_dir = false
6
6
$restart = false
7
7
$root_password = ' UNSET'
8
+ $install_secret_file = ' /.mysql_secret'
8
9
$server_package_ensure = ' present'
9
10
$server_package_manage = true
10
11
$server_service_manage = true
Original file line number Diff line number Diff line change 3
3
$config_file = $mysql::params::config_file,
4
4
$includedir = $mysql::params::includedir,
5
5
$install_options = undef ,
6
+ $install_secret_file = $mysql::params::install_secret_file,
6
7
$manage_config_file = $mysql::params::manage_config_file,
7
8
$override_options = {},
8
9
$package_ensure = $mysql::params::server_package_ensure ,
Original file line number Diff line number Diff line change 2
2
class mysql::server::root_password {
3
3
4
4
$options = $mysql::server::options
5
+ $secret_file = $mysql::server::install_secret_file
6
+
7
+ # New installations of MySQL will configure a default random password for the root user
8
+ # with an expiration. No actions can be performed until this password is changed. The
9
+ # below exec will remove this default password. If the user has supplied a root
10
+ # password it will be set further down with the mysql_user resource.
11
+ $rm_pass_cmd = join([
12
+ " mysqladmin -u root --password=\$ (grep -o '[^ ]\\ +\$ ' ${secret_file} ) password ''" ,
13
+ " rm -f ${secret_file} "
14
+ ], ' && ' )
15
+ exec { 'remove install pass' :
16
+ command => $rm_pass_cmd ,
17
+ onlyif => " test -f ${secret_file} " ,
18
+ path => ' /bin:/sbin:/usr/bin:/usr/sbin:/usr/local/bin:/usr/local/sbin'
19
+ }
5
20
6
21
# manage root password if it is set
7
22
if $mysql::server::create_root_user == true and $mysql::server::root_password != ' UNSET' {
8
23
mysql_user { 'root@localhost' :
9
24
ensure => present ,
10
25
password_hash => mysql_password($mysql::server::root_password ),
26
+ require => Exec[' remove install pass' ]
11
27
}
12
28
}
13
29
Original file line number Diff line number Diff line change 69
69
70
70
context 'mysql::server::root_password' do
71
71
describe 'when defaults' do
72
+ it {
73
+ is_expected . to contain_exec ( 'remove install pass' ) . with (
74
+ :command => 'mysqladmin -u root --password=$(grep -o \'[^ ]\\+$\' /.mysql_secret) password \'\' && rm -f /.mysql_secret' ,
75
+ :onlyif => 'test -f /.mysql_secret' ,
76
+ :path => '/bin:/sbin:/usr/bin:/usr/sbin:/usr/local/bin:/usr/local/sbin'
77
+ )
78
+ }
72
79
it { is_expected . not_to contain_mysql_user ( 'root@localhost' ) }
73
80
it { is_expected . not_to contain_file ( '/root/.my.cnf' ) }
74
81
end
92
99
it { is_expected . not_to contain_mysql_user ( 'root@localhost' ) }
93
100
it { is_expected . not_to contain_file ( '/root/.my.cnf' ) }
94
101
end
102
+ describe 'when install_secret_file set to /root/.mysql_secret' do
103
+ let ( :params ) { { :install_secret_file => '/root/.mysql_secret' } }
104
+ it {
105
+ is_expected . to contain_exec ( 'remove install pass' ) . with (
106
+ :command => 'mysqladmin -u root --password=$(grep -o \'[^ ]\\+$\' /root/.mysql_secret) password \'\' && rm -f /root/.mysql_secret' ,
107
+ :onlyif => 'test -f /root/.mysql_secret'
108
+ )
109
+ }
110
+ end
95
111
end
96
112
97
113
context 'mysql::server::providers' do
You can’t perform that action at this time.
0 commit comments