File tree 4 files changed +35
-0
lines changed
4 files changed +35
-0
lines changed Original file line number Diff line number Diff line change 6
6
$purge_conf_dir = false
7
7
$restart = false
8
8
$root_password = ' UNSET'
9
+ $install_secret_file = ' /.mysql_secret'
9
10
$server_package_ensure = ' present'
10
11
$server_package_manage = true
11
12
$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
$old_root_password = $mysql::params::old_root_password,
8
9
$override_options = {},
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
+ " echo \$ (grep -o '[^ ]\\ +\$ ' ${secret_file} )" ,
14
+ " rm -f ${secret_file} "
15
+ ], ' && ' )
16
+ exec { "remove install password" :
17
+ command => $rm_pass_cmd ,
18
+ onlyif => " test -f ${secret_file} " ,
19
+ path => " /bin:/sbin:/usr/bin:/usr/sbin:/usr/local/bin:/usr/local/sbin"
20
+ }
5
21
6
22
# manage root password if it is set
7
23
if $mysql::server::create_root_user == true and $mysql::server::root_password != ' UNSET' {
8
24
mysql_user { 'root@localhost' :
9
25
ensure => present ,
10
26
password_hash => mysql_password($mysql::server::root_password ),
27
+ require => Exec[' remove install password' ]
11
28
}
12
29
}
13
30
Original file line number Diff line number Diff line change 61
61
62
62
context 'mysql::server::root_password' do
63
63
describe 'when defaults' do
64
+ it {
65
+ is_expected . to contain_exec ( 'remove install pass' ) . with {
66
+ :command => 'mysqladmin -u root --password=$(grep -o \'[^ ]\\+$\' /.mysql_secret) password \'\' && rm -f /.mysql_secret' ,
67
+ :test => 'test -f /root/.mysql_secret' ,
68
+ :path => '/bin:/sbin:/usr/bin:/usr/sbin:/usr/local/bin:/usr/local/sbin'
69
+ }
70
+ }
64
71
it { is_expected . not_to contain_mysql_user ( 'root@localhost' ) }
65
72
it { is_expected . not_to contain_file ( '/root/.my.cnf' ) }
66
73
end
84
91
it { is_expected . not_to contain_mysql_user ( 'root@localhost' ) }
85
92
it { is_expected . not_to contain_file ( '/root/.my.cnf' ) }
86
93
end
94
+ describe 'when install_secret_file set to /root/.mysql_secret' do
95
+ let ( :params ) { { :install_secret_file => '/root/.mysql_secret' } }
96
+ it {
97
+ is_expected . to contain_exec ( 'remove install pass' ) . with {
98
+ :command => 'mysqladmin -u root --password=$(grep -o \'[^ ]\\+$\' /root/.mysql_secret) password \'\' && rm -f /root/.mysql_secret' ,
99
+ :test => 'test -f /root/.mysql_secret'
100
+ }
101
+ }
102
+ end
87
103
end
88
104
89
105
context 'mysql::server::providers' do
You can’t perform that action at this time.
0 commit comments