Ansible module with mysql_user fails to create new user, if option encrypted is set
Affects | Status | Importance | Assigned to | Milestone | |
---|---|---|---|---|---|
ansible (Ubuntu) |
Confirmed
|
Undecided
|
Unassigned |
Bug Description
With MySQL version 8.0, the ansible mysql module runs into an error while creating a new MySQL user with the option "encrypted: yes" (if the MySQL user does not exist yet).
The Bug appears to be in the 'user_add' function in file '/usr/lib/
def user_add(cursor, user, host, host_all, password, encrypted, new_priv, check_mode):
# we cannot create users without a proper hostname
if host_all:
return False
if check_mode:
return True
if password and encrypted:
---> cursor.
elif password and not encrypted:
else:
if new_priv is not None:
for db_table, priv in iteritems(
return True
Ansible translates this to and tries to execute the following MySQL command which fails (here the output from mysql after retrying):
mysql> CREATE USER 'newuser'
ERROR 1064 (42000): You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'PASSWORD "*1234567890123
The following MySQL command actually does what I am trying to accomplish:
mysql> CREATE USER 'newuser'
Query OK, 0 rows affected (0.01 sec)
---
ansible-playbook version: 2.9.9
python version = 3.8.6 (default, Jan 27 2021, 15:42:20) [GCC 10.2.0]
Looks like this has been fixed for later versions of Ansible, however version 2.9.X ships with Ubuntu focal and groovy. (The LTS release focal will still be around for some time.)
Adding a patch to mirror the following code (along with the function impl.supports_ identified_ by_password( ) )
if password and encrypted: identified_ by_password( cursor) :
query_ with_args = "CREATE USER %s@%s IDENTIFIED BY PASSWORD %s", (user, host, password)
query_ with_args = "CREATE USER %s@%s IDENTIFIED WITH mysql_native_ password AS %s", (user, host, password)
if impl.supports_
else:
would certainly help.