From 40ef07a286a1617d6697297cc678bbc9b79d64e2 Mon Sep 17 00:00:00 2001 From: Jonathan Mainguy Date: Fri, 11 Jul 2014 14:57:45 -0400 Subject: [PATCH] Errors out with stderr 1049, unknown database: when importing a database that does not exist --- library/database/mysql_db | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/library/database/mysql_db b/library/database/mysql_db index 6b6639da8e..40af38108f 100644 --- a/library/database/mysql_db +++ b/library/database/mysql_db @@ -314,7 +314,11 @@ def main(): db_connection = MySQLdb.connect(host=module.params["login_host"], port=int(module.params["login_port"]), user=login_user, passwd=login_password, db=connect_to_db) cursor = db_connection.cursor() except Exception, e: - module.fail_json(msg="unable to connect, check login_user and login_password are correct, or alternatively check ~/.my.cnf contains credentials") + 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_user and login_password are correct, or alternatively check ~/.my.cnf contains credentials") changed = False if db_exists(cursor, db):