From 8f8109f1e0cfaefd5270358dd72ab35ced271dcb Mon Sep 17 00:00:00 2001 From: Johann Schmitz Date: Tue, 26 May 2015 16:13:40 +0200 Subject: [PATCH] Improved output of mysql_db plugin Show error number and error description on connect error to ease debugging. --- lib/ansible/modules/database/mysql/mysql_db.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/ansible/modules/database/mysql/mysql_db.py b/lib/ansible/modules/database/mysql/mysql_db.py index 05db6beb07f..b9d862b56ac 100644 --- a/lib/ansible/modules/database/mysql/mysql_db.py +++ b/lib/ansible/modules/database/mysql/mysql_db.py @@ -346,11 +346,11 @@ def main(): db_connection = MySQLdb.connect(host=module.params["login_host"], port=login_port, user=login_user, passwd=login_password, db=connect_to_db) cursor = db_connection.cursor() except Exception, e: + errno, errstr = e.args if "Unknown database" in str(e): - errno, errstr = e.args module.fail_json(msg="ERROR: %s %s" % (errno, errstr)) else: - module.fail_json(msg="unable to connect, check login credentials (login_user, and login_password, which can be defined in ~/.my.cnf), check that mysql socket exists and mysql server is running") + module.fail_json(msg="unable to connect, check login credentials (login_user, and login_password, which can be defined in ~/.my.cnf), check that mysql socket exists and mysql server is running (ERROR: %s %s)" % (errno, errstr)) changed = False if db_exists(cursor, db):