From 20542419200aa8534ee9f04be125e77389c886c7 Mon Sep 17 00:00:00 2001 From: Laurent Indermuehle Date: Thu, 14 Sep 2023 11:17:47 +0200 Subject: [PATCH] Fix KeyError 0 --- 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 fcb862c..44c6a0d 100644 --- a/plugins/module_utils/user.py +++ b/plugins/module_utils/user.py @@ -480,10 +480,12 @@ def privileges_get(module, cursor, user, host, maria_role=False): return x for grant in grants: + grant = list(grant.values()) + if not maria_role: - res = re.match("""GRANT (.+) ON (.+) TO (['`"]).*\\3@(['`"]).*\\4( IDENTIFIED BY PASSWORD (['`"]).+\\6)? ?(.*)""", grant) + res = re.match("""GRANT (.+) ON (.+) TO (['`"]).*\\3@(['`"]).*\\4( IDENTIFIED BY PASSWORD (['`"]).+\\6)? ?(.*)""", grant[0]) else: - res = re.match("""GRANT (.+) ON (.+) TO (['`"]).*\\3""", grant) + res = re.match("""GRANT (.+) ON (.+) TO (['`"]).*\\3""", grant[0]) if res is None: # If a user has roles assigned, we'll have one of priv tuples looking like @@ -491,11 +493,11 @@ def privileges_get(module, cursor, user, host, maria_role=False): # which will result None as res value. # As we use the mysql_role module to manipulate roles # we just ignore such privs below: - res = re.match("""GRANT (.+) TO (['`"]).*""", grant) + res = re.match("""GRANT (.+) TO (['`"]).*""", grant[0]) if not maria_role and res: continue - raise InvalidPrivsError('unable to parse the MySQL grant string: %s' % grant) + raise InvalidPrivsError('unable to parse the MySQL grant string: %s' % grant[0]) privileges = res.group(1).split(",") privileges = [pick(x.strip()) for x in privileges]