mysql_db module issue

Hello,

I have an old task that works on an previous system but fail to work in the new system. I am certain it hasn’t changed through git log but I have updated ansible on control system. I don’t see other people raising the issue so not confident it’s a bug. Have anyone observed something similar?

Version:
control machine: Centos 7
managed system: RHEL 7
ansible: ansible-2.7.9-1.el7.noarch

Task currently:

  • name: create projectsend database schema
    mysql_db: name={{database_name}} encoding=utf8mb4 collation=utf8mb4_bin state=present state=present login_user=root login_password=“{{root_db_password}}”

Task previously:

  • name: create projectsend database schema
    mysql_db: name={{database_name}} encoding=utf8mb4 collation=utf8mb4_bin state=present state=present

None of the above tasks works on a new system, they work fine though on a previous system. I can login fine to mysql without having to use the password, so details on /root/.my.cnf are fine. What could be causing this?

The full traceback is:
WARNING: The below traceback may not be related to the actual failure.
File “/tmp/ansible_mysql_db_payload_bZdCNZ/main.py”, line 316, in main
connect_timeout=connect_timeout)
File “/tmp/ansible_mysql_db_payload_bZdCNZ/ansible_mysql_db_payload.zip/ansible/module_utils/mysql.py”, line 79, in mysql_connect
db_connection = mysql_driver.connect(**config)
File “/usr/lib/python2.7/site-packages/pymysql/init.py”, line 94, in Connect
return Connection(*args, **kwargs)
File “/usr/lib/python2.7/site-packages/pymysql/connections.py”, line 327, in init
self.connect()
File “/usr/lib/python2.7/site-packages/pymysql/connections.py”, line 598, in connect
self._request_authentication()
File “/usr/lib/python2.7/site-packages/pymysql/connections.py”, line 862, in _request_authentication
auth_packet = self._process_auth(plugin_name, auth_packet)
File “/usr/lib/python2.7/site-packages/pymysql/connections.py”, line 933, in _process_auth
pkt = self._read_packet()
File “/usr/lib/python2.7/site-packages/pymysql/connections.py”, line 683, in _read_packet
packet.check_error()
File “/usr/lib/python2.7/site-packages/pymysql/protocol.py”, line 220, in check_error
err.raise_mysql_exception(self._data)
File “/usr/lib/python2.7/site-packages/pymysql/err.py”, line 109, in raise_mysql_exception
raise errorclass(errno, errval)

fatal: [projectsend.eng.example.com]: FAILED! => {
“changed”: false,
“invocation”: {
“module_args”: {
“collation”: “utf8mb4_bin”,
“config_file”: “/root/.my.cnf”,
“connect_timeout”: 30,
“encoding”: “utf8mb4”,
“ignore_tables”: ,
“login_host”: “localhost”,
“login_password”: “VALUE_SPECIFIED_IN_NO_LOG_PARAMETER”,
“login_port”: 3306,
“login_unix_socket”: null,
“login_user”: “root”,
“name”: “projectsend_db”,
“quick”: true,
“single_transaction”: false,
“ssl_ca”: null,
“ssl_cert”: null,
“ssl_key”: null,
“state”: “present”,
“target”: null
}
},
“msg”: “unable to connect to database, check login_user and login_password are correct or /root/.my.cnf has the credentials. Exception message: (1045, u"Access denied for user ‘root’@‘localhost’ (using password: YES)")”
}
to retry, use: --limit @/etc/ansible/site.retry

PLAY RECAP ********************************************************************************************************************************************************************************************************
projectsend.eng.example.com : ok=3 changed=0 unreachable=0 failed=1

Regard,
William

Hi,

it could be related to the change from MySQLdb to PyMySQL; see
https://github.com/ansible/ansible/issues/47736 and in particular
https://github.com/ansible/ansible/issues/47736#issuecomment-479745979

I wouldn't be surprised if you have PyMySQL installed on the new
system, and MySQLdb installed on the old one. That would explain why
one works and the other doesn't.

Cheers,
Felix