Hi all,
As you know, when you install MySQL 5.6 it sets you DB with a random password stored on /root/.mysql_secret file. This fact it give me a lot of troubles since I need to edit my Mysql role since before you could login first time to Mysql without passwords. I’m trying to find out a workaround, but it does not like too much and does not work properly:
Ugly: Mysql-5.6 sets a random password and we need to catch it
-
name: Update first time password
shell: mysqladmin -uroot -p$(awk ‘{print $NF}’ /root/.mysql_secret | head -n1) password {{ mysql_root_password }} || true
ignore_errors: True
tags: -
mysql-pw
-
name: Create .my.cnf file with root password credentials
template: src=mysql/root/my.cnf dest=/root/.my.cnf owner=root mode=0600
tags: -
mysql-pw
Mysql 5.6 conflicts with this task
- name: Update mysql root password for all root accounts
mysql_user: name=root host={{ item }} password={{ mysql_root_password }} priv=.:ALL,GRANT state=present
with_items: - 127.0.0.1
- ::1
- localhost
tags: - mysql-pw
It works great the first run, since:
1.- it change default random password for my variable password
2.- it creates the .my.cnf file with that new password
3.- Ansible is able to connect to ensure root password is well set.
What happens if I want to change again the new password:
1.- Skip the first task since mysqladmin login fails (ugly)
2.- It changes the .my.cnf file when the password has not been changes on MySQL
3.- Ansible tries to login to MySQL through the password stored in .my.cnf => FAIL
Thoughts how to solve it?
Thanks in advance !