From 31a5eb8739fc64b92896c1137861bc0027e4b112 Mon Sep 17 00:00:00 2001 From: Laurent Indermuehle Date: Mon, 11 Sep 2023 19:40:14 +0200 Subject: [PATCH] Debug error "0" This debug output this: [ {'Grants for root@localhost': \"GRANT ALL PRIVILEGES ON *.* TO 'root'@'localhost' WITH GRANT OPTION\"}, {'Grants for root@localhost': \"GRANT PROXY ON ''@'' TO 'root'@'localhost' WITH GRANT OPTION\"} ], [ {'Grants for mysql.session@localhost': \"GRANT SUPER ON *.* TO 'mysql.session'@'localhost'\"}, {'Grants for mysql.session@localhost': \"GRANT SELECT ON `performance_schema`.* TO 'mysql.session'@'localhost'\"}, {'Grants for mysql.session@localhost': \"GRANT SELECT ON `mysql`.`user` TO 'mysql.session'@'localhost'\"} ], [ {'Grants for mysql.sys@localhost': \"GRANT USAGE ON *.* TO 'mysql.sys'@'localhost'\"}, {'Grants for mysql.sys@localhost': \"GRANT TRIGGER ON `sys`.* TO 'mysql.sys'@'localhost'\"}, {'Grants for mysql.sys@localhost': \"GRANT SELECT ON `sys`.`sys_config` TO 'mysql.sys'@'localhost'\"} ], [ {'Grants for root@%': \"GRANT ALL PRIVILEGES ON *.* TO 'root'@'%' WITH GRANT OPTION\"} ] I think something is wrong in the lambda and when grants art on ''@''. --- plugins/module_utils/user.py | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/plugins/module_utils/user.py b/plugins/module_utils/user.py index 1434b3b..4f783a2 100644 --- a/plugins/module_utils/user.py +++ b/plugins/module_utils/user.py @@ -107,13 +107,16 @@ def get_tls_requires(cursor, user, host): def get_grants(module, cursor, user, host): cursor.execute("SHOW GRANTS FOR %s@%s", (user, host)) try: - grants_line = list(filter(lambda x: "ON *.*" in x[0], cursor.fetchall()))[0] + c = cursor.fetchall() + # grants_line = list(filter(lambda x: "ON *.*" in x[0], cursor.fetchall()))[0] + module.warn("%s" % c) except Exception as e: module.fail_json(msg="Error %s" % e) - pattern = r"(?<=\bGRANT\b)(.*?)(?=(?:\bON\b))" - grants = re.search(pattern, grants_line[0]).group().strip() - return grants.split(", ") + # pattern = r"(?<=\bGRANT\b)(.*?)(?=(?:\bON\b))" + # grants = re.search(pattern, grants_line[0]).group().strip() + # return grants.split(", ") + return "test" def get_existing_authentication(cursor, user):