I'm attempting to modify the opscode-mysql cookbook to add support for the
MySQL 5.6 RHEL binaries. Since MySQL 5.6.8, the RPM package install adds the
--random-password flag to mysql_install_db which generates a random password at
package install time and stores it in /root/.mysql_secret. I need to parse the
file and extract the password *after* the package has been installed and pass
it into the execute["assign-root-password"] resource.
The file looks like this:
# The random password set for the root user at Mon Mar 25 21:59:23 2013
(local time): abcdefg
I can extract the password with this (simplified) code:
if ::File.file?('/root/.mysql_secret')
initial_password =
::File.readlines(mysql_secret_file).grep(/random/).last.split(': ').last.chomp
end
initial_password_param = initial_password ? "-p#{initial_password}" : ""
Because chef executes ruby code before the resources are executed, I can't
figure out how to extract that temporary random password after the package
install and pass it to execute[assign-root-password].
Ideally, I'd like to be able to do something like this:
execute "assign-root-password" do
command "\"#{node['mysql']['mysqladmin_bin']}\" -u root
#{initial_password_param} password
\"#{node['mysql']['server_root_password']}\""
action :run
only_if "\"#{node['mysql']['mysql_bin']}\" -u root
#{initial_password_param} -e 'show databases;'"
end
I've thought about using a ruby_block, but I can't see a way to pass the
variable into the execute.
Hopefully this is more clear than mud. Thanks in advance for any assistance!
Aaron
Archive powered by MHonArc 2.6.16.