From 839d5b6de40f453381fe2e972f4e2bb81d2a5221 Mon Sep 17 00:00:00 2001 From: Michael Scherer Date: Wed, 31 Aug 2016 17:07:32 +0200 Subject: [PATCH] Fix mysql_user for python3 (#4576) dict no longer have a iteritems method, it was replaced by items. So we need to use six. Traceback (most recent call last): File \"/tmp/ansible_hjd7d65c/ansible_module_mysql_user.py\", line 587, in main() File \"/tmp/ansible_hjd7d65c/ansible_module_mysql_user.py\", line 571, in main changed = user_add(cursor, user, host, host_all, password, encrypted, priv, module.check_mode) File \"/tmp/ansible_hjd7d65c/ansible_module_mysql_user.py\", line 239, in user_add for db_table, priv in new_priv.iteritems(): AttributeError: 'dict' object has no attribute 'iteritems' --- lib/ansible/modules/database/mysql/mysql_user.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/lib/ansible/modules/database/mysql/mysql_user.py b/lib/ansible/modules/database/mysql/mysql_user.py index 238e2a9cfca..7f97a182068 100644 --- a/lib/ansible/modules/database/mysql/mysql_user.py +++ b/lib/ansible/modules/database/mysql/mysql_user.py @@ -166,6 +166,7 @@ except ImportError: mysqldb_found = False else: mysqldb_found = True +from ansible.module_utils.six import iteritems VALID_PRIVS = frozenset(('CREATE', 'DROP', 'GRANT', 'GRANT OPTION', 'LOCK TABLES', 'REFERENCES', 'EVENT', 'ALTER', @@ -234,9 +235,8 @@ def user_add(cursor, user, host, host_all, password, encrypted, new_priv, check_ cursor.execute("CREATE USER %s@%s IDENTIFIED BY %s", (user,host,password)) else: cursor.execute("CREATE USER %s@%s", (user,host)) - if new_priv is not None: - for db_table, priv in new_priv.iteritems(): + for db_table, priv in iteritems(new_priv): privileges_grant(cursor, user,host,db_table,priv) return True @@ -309,7 +309,7 @@ def user_mod(cursor, user, host, host_all, password, encrypted, new_priv, append # If the user has privileges on a db.table that doesn't appear at all in # the new specification, then revoke all privileges on it. - for db_table, priv in curr_priv.iteritems(): + for db_table, priv in iteritems(curr_priv): # If the user has the GRANT OPTION on a db.table, revoke it first. if "GRANT" in priv: grant_option = True @@ -322,7 +322,7 @@ def user_mod(cursor, user, host, host_all, password, encrypted, new_priv, append # If the user doesn't currently have any privileges on a db.table, then # we can perform a straight grant operation. - for db_table, priv in new_priv.iteritems(): + for db_table, priv in iteritems(new_priv): if db_table not in curr_priv: if module.check_mode: return True