Since 6 hours I'm trying to find out how ansible wants to work with my mariadb on ubuntu 16.
When I manually log in on the server with
mysql -u someuser -p
everything works fine
when I try to access the server with the ansible script with:
- name: Create mysql database
mysql_user: name=someuser state=present password=somepw
its complaining:
fatal: [IP]: FAILED! => {"changed": false, "failed": true, "msg": "unable to connect to database, check login_user and login_password are correct or /home/someuser/.my.cnf has the credentials. Exception message: (2002, \"Can't connect to local MySQL server through socket '/tmp/mysql.sock' (2)\")"}
Then I try to put .my.cnf into the directory on the remote server like it is trying to tell me. I also added login_user and login_password. No help.
The file looks like this:
/home/someuser/.my.cnf
[client]
user=someuser
password=somepw
"Okay" I thought. Maybe the credentials are doubled in the ansible script and in the conf file. I tried to leave the conf file or to skip the credentials in the ansible script. No help
I also restarted the mysql server. No help. The strange thing is, that from the server itself everything worked with the mysql shell. I'm really struggleing to find the solution. Shouldn't this work just like a charm?
Okay figured it out. Ubuntu 16 in my case puts the socket file into
/var/run/mysqld/mysqld.sock
where ansible isn't expecting it. So for me it worked to put login_unix_socket into the playbook (ansible script)
- name: Create mysql database
mysql_db:
login_unix_socket: /var/run/mysqld/mysqld.sock
name: projectname
state: present
and place .my.cnf like mentioned above.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With