From 5b84b0d136c75ca964d1fcbb8ddc2359a98f9cfe Mon Sep 17 00:00:00 2001 From: acaveroc Date: Wed, 17 Jun 2015 10:37:47 +0200 Subject: [PATCH 1/3] Add port definition support for mysql_vars module --- database/mysql/mysql_variables.py | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/database/mysql/mysql_variables.py b/database/mysql/mysql_variables.py index 0b0face0328..753d37433e3 100644 --- a/database/mysql/mysql_variables.py +++ b/database/mysql/mysql_variables.py @@ -52,6 +52,10 @@ options: description: - mysql host to connect required: False + login_port: + description: + - mysql port to connect + required: False login_unix_socket: description: - unix socket to connect mysql server @@ -194,6 +198,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), variable=dict(default=None), value=dict(default=None) @@ -203,6 +208,7 @@ def main(): user = module.params["login_user"] password = module.params["login_password"] host = module.params["login_host"] + port = module.params["login_port"] mysqlvar = module.params["variable"] value = module.params["value"] if not mysqldb_found: @@ -227,9 +233,9 @@ def main(): module.fail_json(msg="when supplying login arguments, both login_user and login_password must be provided") try: 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") + db_connection = MySQLdb.connect(host=module.params["login_host"], port=module.params["login_port"], 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=module.params["login_port"], user=login_user, passwd=login_password, db="mysql") cursor = db_connection.cursor() except Exception, e: module.fail_json(msg="unable to connect to database, check login_user and login_password are correct or ~/.my.cnf has the credentials") From 7d2a5965bd5fc95196a3d3427acaa5ca086e4e80 Mon Sep 17 00:00:00 2001 From: acaveroc Date: Wed, 17 Jun 2015 13:53:08 +0200 Subject: [PATCH 2/3] Assorted minor bug fixes - Modified data type for port definition from string to integer - Modified login_host default value for compatibilize with port definition according with MySQL Documentation (https://dev.mysql.com/doc/refman/5.0/en/connecting.html) --- database/mysql/mysql_variables.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/database/mysql/mysql_variables.py b/database/mysql/mysql_variables.py index 753d37433e3..36415df5460 100644 --- a/database/mysql/mysql_variables.py +++ b/database/mysql/mysql_variables.py @@ -197,7 +197,7 @@ def main(): argument_spec = dict( login_user=dict(default=None), login_password=dict(default=None), - login_host=dict(default="localhost"), + login_host=dict(default="127.0.0.1"), login_port=dict(default="3306"), login_unix_socket=dict(default=None), variable=dict(default=None), @@ -233,9 +233,9 @@ def main(): module.fail_json(msg="when supplying login arguments, both login_user and login_password must be provided") try: if module.params["login_unix_socket"]: - db_connection = MySQLdb.connect(host=module.params["login_host"], port=module.params["login_port"], unix_socket=module.params["login_unix_socket"], user=login_user, passwd=login_password, db="mysql") + db_connection = MySQLdb.connect(host=module.params["login_host"], port=int(module.params["login_port"]), 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"], port=module.params["login_port"], 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") cursor = db_connection.cursor() except Exception, e: module.fail_json(msg="unable to connect to database, check login_user and login_password are correct or ~/.my.cnf has the credentials") From e7876df99f7e68467c0c6da0939fb5ba07f9ee14 Mon Sep 17 00:00:00 2001 From: acaveroc Date: Thu, 18 Jun 2015 09:43:32 +0200 Subject: [PATCH 3/3] Add version_added and type of parameter --- database/mysql/mysql_variables.py | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/database/mysql/mysql_variables.py b/database/mysql/mysql_variables.py index 36415df5460..f50ed740539 100644 --- a/database/mysql/mysql_variables.py +++ b/database/mysql/mysql_variables.py @@ -53,6 +53,7 @@ options: - mysql host to connect required: False login_port: + version_added: "1.9" description: - mysql port to connect required: False @@ -198,7 +199,7 @@ def main(): login_user=dict(default=None), login_password=dict(default=None), login_host=dict(default="127.0.0.1"), - login_port=dict(default="3306"), + login_port=dict(default="3306", type='int'), login_unix_socket=dict(default=None), variable=dict(default=None), value=dict(default=None) @@ -233,9 +234,9 @@ def main(): module.fail_json(msg="when supplying login arguments, both login_user and login_password must be provided") try: if module.params["login_unix_socket"]: - db_connection = MySQLdb.connect(host=module.params["login_host"], port=int(module.params["login_port"]), unix_socket=module.params["login_unix_socket"], user=login_user, passwd=login_password, db="mysql") + db_connection = MySQLdb.connect(host=module.params["login_host"], port=module.params["login_port"], 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"], port=int(module.params["login_port"]), user=login_user, passwd=login_password, db="mysql") + db_connection = MySQLdb.connect(host=module.params["login_host"], port=module.params["login_port"], user=login_user, passwd=login_password, db="mysql") cursor = db_connection.cursor() except Exception, e: module.fail_json(msg="unable to connect to database, check login_user and login_password are correct or ~/.my.cnf has the credentials")