From 6f147bd0c140082413e433da0c5d552a9f1342d3 Mon Sep 17 00:00:00 2001 From: Ingo Gottwald Date: Fri, 3 Aug 2012 12:34:55 +0200 Subject: [PATCH 1/2] Added login_unix_socket option to mysql_db module --- mysql_db | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/mysql_db b/mysql_db index 1818b8e95ab..6752d9f7ba3 100755 --- a/mysql_db +++ b/mysql_db @@ -71,6 +71,7 @@ def main(): login_user=dict(default=None), login_password=dict(default=None), login_host=dict(default="localhost"), + login_unix_socket=dict(default=None), db=dict(required=True, aliases=['name']), encoding=dict(default=""), collation=dict(default=""), @@ -103,7 +104,10 @@ def main(): module.fail_json(msg="when supplying login arguments, both login_user and login_password must be provided") try: - db_connection = MySQLdb.connect(host=module.params["login_host"], user=login_user, passwd=login_password, db="mysql") + if module.params["login_unix_socket"] != None: + 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") cursor = db_connection.cursor() except Exception as e: module.fail_json(msg="unable to connect, check login_user and login_password are correct, or alternatively check ~/.my.cnf contains credentials") From b81b4510385bc0764d79995d7e3d59def1bee839 Mon Sep 17 00:00:00 2001 From: Ingo Gottwald Date: Fri, 3 Aug 2012 12:35:18 +0200 Subject: [PATCH 2/2] Added login_unix_socket option to mysql_user module --- mysql_user | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/mysql_user b/mysql_user index b09b1fbd19a..5a4062b68d2 100755 --- a/mysql_user +++ b/mysql_user @@ -164,6 +164,7 @@ def main(): login_user=dict(default=None), login_password=dict(default=None), login_host=dict(default="localhost"), + login_unix_socket=dict(default=None), user=dict(required=True, aliases=['name']), password=dict(default=None), host=dict(default="localhost"), @@ -203,7 +204,10 @@ def main(): module.fail_json(msg="when supplying login arguments, both login_user and login_password must be provided") try: - db_connection = MySQLdb.connect(host=module.params["login_host"], user=login_user, passwd=login_password, db="mysql") + if module.params["login_unix_socket"] != None: + 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") cursor = db_connection.cursor() except Exception as e: module.fail_json(msg="unable to connect to database, check login_user and login_password are correct or ~/.my.cnf has the credentials")