~/.my.cnf path

Hi,

Question about the location of ~/.my.cnf . For ansible, would this refer to the “become” user’s home directory ( which is /root/.my.cnf ), or the ansible user’s home directory ( such as, during testing, /home/vagrant/.my.cnf ) ?

It seems that mysql_user module is looking for the ansible user’s home directory because I get an error “msg”: “unable to connect to database, check login_user and login_password are correct or /home/vagrant/.my.cnf has the credentials. Exception message: (1045, "Access denied for user ‘root’@‘localhost’ (using password: NO)")”}

which then leads to the next question, what does the copy module consider to be ~/.my.cnf ?

  • name: create .my.cnf file
    copy: content=“[client]\nuser=root\npassword={{ mysql_root_password }}” dest=~/.my.cnf

This places the file in /root/.my.cnf

The copy module and mysql_user module do not interpret the same ~/.my.cnf ?

More information:

In http://docs.ansible.com/ansible/mysql_user_module.html it says “MySQL server installs with default login_user of ‘root’ and no password. To secure this user as part of an idempotent playbook, you must create at least two tasks: the first must change the root user’s password, without providing any login_user/login_password details. The second must drop a ~/.my.cnf file containing the new root credentials. Subsequent runs of the playbook will then succeed by reading the new credentials from the file.”