Expand tildes and vars in the config file path

This commit is contained in:
Toshio Kuratomi 2015-05-08 10:40:26 -07:00
parent 296691d34d
commit 8b4e201772

View file

@ -182,7 +182,7 @@ class InvalidPrivsError(Exception):
# MySQL module specific support methods. # MySQL module specific support methods.
# #
def connect(module, login_user=None, login_password=None, config_file='~/.my.cnf'): def connect(module, login_user=None, login_password=None, config_file=''):
config = { config = {
'host': module.params['login_host'], 'host': module.params['login_host'],
'db': 'mysql' 'db': 'mysql'
@ -403,6 +403,7 @@ def main():
append_privs = module.boolean(module.params["append_privs"]) append_privs = module.boolean(module.params["append_privs"])
update_password = module.params['update_password'] update_password = module.params['update_password']
config_file = os.path.expanduser(os.path.expandvars(config_file))
if not mysqldb_found: if not mysqldb_found:
module.fail_json(msg="the python mysqldb module is required") module.fail_json(msg="the python mysqldb module is required")
@ -423,7 +424,7 @@ def main():
if not cursor: if not cursor:
cursor = connect(module, login_user, login_password, config_file) cursor = connect(module, login_user, login_password, config_file)
except Exception, e: 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") module.fail_json(msg="unable to connect to database, check login_user and login_password are correct or ~/.my.cnf has the credentials. Exception message: %s" % e)
if state == "present": if state == "present":
if user_exists(cursor, user, host): if user_exists(cursor, user, host):