From 8d80ffd8cabdaddbfc11c3569bb338b80f006d16 Mon Sep 17 00:00:00 2001 From: Andrew Klychkov Date: Mon, 15 Jun 2020 09:12:20 +0300 Subject: [PATCH] mysql_user: fix cursor-related host_all arguments conversion string formatting error (#490) * mysql_user: fix cursor-related host_all arguments conversion string formatting error * add changelog fragment --- changelogs/fragments/490-mysql_user_fix_cursor_errors.yml | 2 ++ plugins/modules/database/mysql/mysql_user.py | 6 +++--- 2 files changed, 5 insertions(+), 3 deletions(-) create mode 100644 changelogs/fragments/490-mysql_user_fix_cursor_errors.yml diff --git a/changelogs/fragments/490-mysql_user_fix_cursor_errors.yml b/changelogs/fragments/490-mysql_user_fix_cursor_errors.yml new file mode 100644 index 0000000000..564b8d77b8 --- /dev/null +++ b/changelogs/fragments/490-mysql_user_fix_cursor_errors.yml @@ -0,0 +1,2 @@ +bugfixes: +- mysql_user - fix ``host_all`` arguments conversion string formatting error (https://github.com/ansible/ansible/issues/29644). diff --git a/plugins/modules/database/mysql/mysql_user.py b/plugins/modules/database/mysql/mysql_user.py index 6e0b21927c..15ecf139c8 100644 --- a/plugins/modules/database/mysql/mysql_user.py +++ b/plugins/modules/database/mysql/mysql_user.py @@ -340,7 +340,7 @@ def get_mode(cursor): def user_exists(cursor, user, host, host_all): if host_all: - cursor.execute("SELECT count(*) FROM mysql.user WHERE user = %s", ([user])) + cursor.execute("SELECT count(*) FROM mysql.user WHERE user = %s", (user,)) else: cursor.execute("SELECT count(*) FROM mysql.user WHERE user = %s AND host = %s", (user, host)) @@ -543,7 +543,7 @@ def user_delete(cursor, user, host, host_all, check_mode): return True if host_all: - hostnames = user_get_hostnames(cursor, [user]) + hostnames = user_get_hostnames(cursor, user) for hostname in hostnames: cursor.execute("DROP USER %s@%s", (user, hostname)) @@ -554,7 +554,7 @@ def user_delete(cursor, user, host, host_all, check_mode): def user_get_hostnames(cursor, user): - cursor.execute("SELECT Host FROM mysql.user WHERE user = %s", user) + cursor.execute("SELECT Host FROM mysql.user WHERE user = %s", (user,)) hostnames_raw = cursor.fetchall() hostnames = []