mirror of
https://github.com/ansible-collections/community.general.git
synced 2024-09-14 20:13:21 +02:00
adds error message if socket does not exist
This commit is contained in:
parent
c57c1ea419
commit
13990e9479
1 changed files with 11 additions and 3 deletions
|
@ -102,6 +102,7 @@ EXAMPLES = '''
|
||||||
import ConfigParser
|
import ConfigParser
|
||||||
import os
|
import os
|
||||||
import pipes
|
import pipes
|
||||||
|
import stat
|
||||||
try:
|
try:
|
||||||
import MySQLdb
|
import MySQLdb
|
||||||
except ImportError:
|
except ImportError:
|
||||||
|
@ -283,6 +284,7 @@ def main():
|
||||||
collation = module.params["collation"]
|
collation = module.params["collation"]
|
||||||
state = module.params["state"]
|
state = module.params["state"]
|
||||||
target = module.params["target"]
|
target = module.params["target"]
|
||||||
|
socket = module.params["login_unix_socket"]
|
||||||
|
|
||||||
# make sure the target path is expanded for ~ and $HOME
|
# make sure the target path is expanded for ~ and $HOME
|
||||||
if target is not None:
|
if target is not None:
|
||||||
|
@ -312,8 +314,14 @@ def main():
|
||||||
else:
|
else:
|
||||||
connect_to_db = 'mysql'
|
connect_to_db = 'mysql'
|
||||||
try:
|
try:
|
||||||
if module.params["login_unix_socket"]:
|
if 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)
|
try:
|
||||||
|
socketmode = os.stat(socket).st_mode
|
||||||
|
if not stat.S_ISSOCK(socketmode):
|
||||||
|
module.fail_json(msg="%s, is not a socket, unable to connect" % socket)
|
||||||
|
except OSError:
|
||||||
|
module.fail_json(msg="%s, does not exist, unable to connect" % socket)
|
||||||
|
db_connection = MySQLdb.connect(host=module.params["login_host"], unix_socket=socket, user=login_user, passwd=login_password, db=connect_to_db)
|
||||||
elif module.params["login_port"] != "3306" and module.params["login_host"] == "localhost":
|
elif module.params["login_port"] != "3306" and module.params["login_host"] == "localhost":
|
||||||
module.fail_json(msg="login_host is required when login_port is defined, login_host cannot be localhost when login_port is defined")
|
module.fail_json(msg="login_host is required when login_port is defined, login_host cannot be localhost when login_port is defined")
|
||||||
else:
|
else:
|
||||||
|
@ -324,7 +332,7 @@ def main():
|
||||||
errno, errstr = e.args
|
errno, errstr = e.args
|
||||||
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_user and login_password are correct, or alternatively check ~/.my.cnf contains credentials")
|
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")
|
||||||
|
|
||||||
changed = False
|
changed = False
|
||||||
if db_exists(cursor, db):
|
if db_exists(cursor, db):
|
||||||
|
|
Loading…
Reference in a new issue