Improved output of mysql_db plugin

Show error number and error description on connect error to ease debugging.
reviewable/pr18780/r1
Johann Schmitz 10 years ago
parent 1736c8dfea
commit 8892aa2bf4

@ -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) 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() cursor = db_connection.cursor()
except Exception, e: except Exception, e:
if "Unknown database" in str(e):
errno, errstr = e.args errno, errstr = e.args
if "Unknown database" in str(e):
module.fail_json(msg="ERROR: %s %s" % (errno, errstr)) module.fail_json(msg="ERROR: %s %s" % (errno, errstr))
else: 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 changed = False
if db_exists(cursor, db): if db_exists(cursor, db):

Loading…
Cancel
Save