Woops, missed the rest of them

reviewable/pr18780/r1
Mark Theunissen 12 years ago
parent b51d6d9fca
commit 812711d530

@ -78,20 +78,20 @@ def main():
# Either the caller passes both a username and password with which to connect to # Either the caller passes both a username and password with which to connect to
# mysql, or they pass neither and allow this module to read the credentials from # mysql, or they pass neither and allow this module to read the credentials from
# ~/.my.cnf. # ~/.my.cnf.
loginpass = module.params["loginpass"] loginpasswd = module.params["loginpasswd"]
loginuser = module.params["loginuser"] loginuser = module.params["loginuser"]
if loginuser is None and loginpass is None: if loginuser is None and loginpasswd is None:
mycnf_creds = load_mycnf() mycnf_creds = load_mycnf()
if mycnf_creds is False: if mycnf_creds is False:
module.fail_json(msg="incomplete login arguments passed and can't find them in ~/.my.cnf") module.fail_json(msg="incomplete login arguments passed and can't find them in ~/.my.cnf")
else: else:
loginuser = mycnf_creds["user"] loginuser = mycnf_creds["user"]
loginpass = mycnf_creds["passwd"] loginpasswd = mycnf_creds["passwd"]
elif loginpass is None or loginuser is None: elif loginpasswd is None or loginuser is None:
module.fail_json(msg="when supplying login arguments, both user and pass must be provided") module.fail_json(msg="when supplying login arguments, both user and pass must be provided")
try: try:
db_connection = MySQLdb.connect(host=module.params["loginhost"], user=loginuser, passwd=loginpass, db="mysql") db_connection = MySQLdb.connect(host=module.params["loginhost"], user=loginuser, passwd=loginpasswd, db="mysql")
cursor = db_connection.cursor() cursor = db_connection.cursor()
except Exception as e: except Exception as e:
module.fail_json(msg="unable to connect to database") module.fail_json(msg="unable to connect to database")

@ -187,20 +187,20 @@ def main():
# Either the caller passes both a username and password with which to connect to # Either the caller passes both a username and password with which to connect to
# mysql, or they pass neither and allow this module to read the credentials from # mysql, or they pass neither and allow this module to read the credentials from
# ~/.my.cnf. # ~/.my.cnf.
loginpass = module.params["loginpass"] loginpasswd = module.params["loginpasswd"]
loginuser = module.params["loginuser"] loginuser = module.params["loginuser"]
if loginuser is None and loginpass is None: if loginuser is None and loginpasswd is None:
mycnf_creds = load_mycnf() mycnf_creds = load_mycnf()
if mycnf_creds is False: if mycnf_creds is False:
module.fail_json(msg="incomplete login arguments passed and can't find them in ~/.my.cnf") module.fail_json(msg="incomplete login arguments passed and can't find them in ~/.my.cnf")
else: else:
loginuser = mycnf_creds["user"] loginuser = mycnf_creds["user"]
loginpass = mycnf_creds["passwd"] loginpasswd = mycnf_creds["passwd"]
elif loginpass is None or loginuser is None: elif loginpasswd is None or loginuser is None:
module.fail_json(msg="when supplying login arguments, both user and pass must be provided") module.fail_json(msg="when supplying login arguments, both user and pass must be provided")
try: try:
db_connection = MySQLdb.connect(host=module.params["loginhost"], user=loginuser, passwd=loginpass, db="mysql") db_connection = MySQLdb.connect(host=module.params["loginhost"], user=loginuser, passwd=loginpasswd, db="mysql")
cursor = db_connection.cursor() cursor = db_connection.cursor()
except Exception as e: except Exception as e:
module.fail_json(msg="unable to connect to database") module.fail_json(msg="unable to connect to database")

Loading…
Cancel
Save