From bd944f7bf96f2eed8223557538eed7051fc5c8cb Mon Sep 17 00:00:00 2001 From: Laurent Indermuehle Date: Thu, 14 Sep 2023 19:22:39 +0200 Subject: [PATCH] add host in case multiple accounts uses the same username --- plugins/module_utils/user.py | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/plugins/module_utils/user.py b/plugins/module_utils/user.py index e7e88fc..2e8f806 100644 --- a/plugins/module_utils/user.py +++ b/plugins/module_utils/user.py @@ -122,12 +122,14 @@ def get_existing_authentication(cursor, user): # when using mysql_native_password cursor.execute("""select plugin, auth from ( select plugin, password as auth from mysql.user where user=%(user)s + and host=%(host)s union select plugin, authentication_string as auth from mysql.user where user=%(user)s - ) x group by plugin, auth limit 2 - """, {'user': user}) + and host=%(host)s) x group by plugin, auth limit 2 + """, {'user': user, 'host': host}) else: - cursor.execute("""select plugin, authentication_string as auth from mysql.user where user=%(user)s - group by plugin, authentication_string limit 2""", {'user': user}) + cursor.execute("""select plugin, authentication_string as auth + from mysql.user where user=%(user)s and host=%(host)s + group by plugin, authentication_string limit 2""", {'user': user, 'host': host}) rows = cursor.fetchall() if isinstance(rows[0], tuple):