From b3646176a973f6cbf504f6a8335d591665183424 Mon Sep 17 00:00:00 2001 From: Tom Dymond Date: Thu, 5 Sep 2013 16:25:34 +0100 Subject: [PATCH] Add option to specify the MySQL server port --- database/mysql_db | 8 +++++++- database/mysql_user | 8 +++++++- 2 files changed, 14 insertions(+), 2 deletions(-) diff --git a/database/mysql_db b/database/mysql_db index fc56c12c9cd..e33dba4caac 100644 --- a/database/mysql_db +++ b/database/mysql_db @@ -48,6 +48,11 @@ options: - Host running the database required: false default: localhost + login_port: + description: + - Port of the MySQL server + required: false + default: 3306 login_unix_socket: description: - The path to a Unix domain socket for local connections @@ -197,6 +202,7 @@ def main(): login_user=dict(default=None), login_password=dict(default=None), login_host=dict(default="localhost"), + login_port=dict(default="3306"), login_unix_socket=dict(default=None), db=dict(required=True, aliases=['name']), encoding=dict(default=""), @@ -242,7 +248,7 @@ def main(): if module.params["login_unix_socket"]: db_connection = MySQLdb.connect(host=module.params["login_host"], unix_socket=module.params["login_unix_socket"], user=login_user, passwd=login_password, db=connect_to_db) else: - db_connection = MySQLdb.connect(host=module.params["login_host"], user=login_user, passwd=login_password, db=connect_to_db) + 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") diff --git a/database/mysql_user b/database/mysql_user index ade11331be9..f6be6be77f1 100644 --- a/database/mysql_user +++ b/database/mysql_user @@ -56,6 +56,11 @@ options: - Host running the database required: false default: localhost + login_port: + description: + - Port of the MySQL server + required: false + default: 3306 login_unix_socket: description: - The path to a Unix domain socket for local connections @@ -326,7 +331,7 @@ def connect(module, login_user, login_password): if module.params["login_unix_socket"]: db_connection = MySQLdb.connect(host=module.params["login_host"], unix_socket=module.params["login_unix_socket"], user=login_user, passwd=login_password, db="mysql") else: - db_connection = MySQLdb.connect(host=module.params["login_host"], user=login_user, passwd=login_password, db="mysql") + db_connection = MySQLdb.connect(host=module.params["login_host"], port=int(module.params["login_port"]), user=login_user, passwd=login_password, db="mysql") return db_connection.cursor() # =========================================== @@ -339,6 +344,7 @@ def main(): login_user=dict(default=None), login_password=dict(default=None), login_host=dict(default="localhost"), + login_port=dict(default="3306"), login_unix_socket=dict(default=None), user=dict(required=True, aliases=['name']), password=dict(default=None),