From e11ea4b4020013f0a183fa9d69fdbd56dc66388e Mon Sep 17 00:00:00 2001 From: Toshio Kuratomi Date: Mon, 12 Jan 2015 14:36:57 -0800 Subject: [PATCH] Also catch mysql errors so we can give the error message back through json rather than tracebacking --- lib/ansible/modules/database/mysql/mysql_user.py | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/lib/ansible/modules/database/mysql/mysql_user.py b/lib/ansible/modules/database/mysql/mysql_user.py index 1ca5372c25f..3590fb8e640 100644 --- a/lib/ansible/modules/database/mysql/mysql_user.py +++ b/lib/ansible/modules/database/mysql/mysql_user.py @@ -498,16 +498,14 @@ def main(): if user_exists(cursor, user, host): try: changed = user_mod(cursor, user, host, password, priv, append_privs) - except SQLParseError, e: + except (SQLParseError, InvalidPrivsError, MySQLdb.Error), e: module.fail_json(msg=str(e)) - except InvalidPrivsError, e: - module.mail_json(msg=str(e)) else: if password is None: module.fail_json(msg="password parameter required when adding a user") try: changed = user_add(cursor, user, host, password, priv) - except SQLParseError, e: + except (SQLParseError, InvalidPrivsError, MySQLdb.Error), e: module.fail_json(msg=str(e)) elif state == "absent": if user_exists(cursor, user, host):