# Ansible and MySQL 5.6 passwords

**URL:** <https://forum.ansible.com/t/ansible-and-mysql-5-6-passwords/13823>\
**Category:** Ansible Project\
**Created:** [November 1, 2013, 10:15am UTC](https://forum.ansible.com/t/ansible-and-mysql-5-6-passwords/13823 "2013-11-01T10:15:59Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![Narcis\_Pillao\_Figuer](https://avatars.discourse-cdn.com/v4/letter/n/b9e5f3/32.png) [@Narcis\_Pillao\_Figuer](https://forum.ansible.com/u/Narcis_Pillao_Figuer)\
**Post date:** [November 1, 2013, 10:15am UTC](https://forum.ansible.com/t/ansible-and-mysql-5-6-passwords/13823/1 "2013-11-01T10:15:59Z")

</div>

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 !
