Merge pull request #1236 from ansible/mysql-login-user-override
Allow playbook specified login_user and login_password to override config file settings
This commit is contained in:
commit
c5f3df809f
1 changed files with 7 additions and 3 deletions
|
@ -182,7 +182,7 @@ class InvalidPrivsError(Exception):
|
||||||
# MySQL module specific support methods.
|
# MySQL module specific support methods.
|
||||||
#
|
#
|
||||||
|
|
||||||
def connect(module, login_user, login_password, config_file='~/.my.cnf'):
|
def connect(module, login_user=None, login_password=None, config_file='~/.my.cnf'):
|
||||||
config = {
|
config = {
|
||||||
'host': module.params['login_host'],
|
'host': module.params['login_host'],
|
||||||
'db': 'mysql'
|
'db': 'mysql'
|
||||||
|
@ -195,8 +195,12 @@ def connect(module, login_user, login_password, config_file='~/.my.cnf'):
|
||||||
|
|
||||||
if os.path.exists(config_file):
|
if os.path.exists(config_file):
|
||||||
config['read_default_file'] = config_file
|
config['read_default_file'] = config_file
|
||||||
else:
|
|
||||||
|
# If login_user or login_password are given, they should override the
|
||||||
|
# config file
|
||||||
|
if login_user is not None:
|
||||||
config['user'] = login_user
|
config['user'] = login_user
|
||||||
|
if login_password is not None:
|
||||||
config['passwd'] = login_password
|
config['passwd'] = login_password
|
||||||
|
|
||||||
db_connection = MySQLdb.connect(**config)
|
db_connection = MySQLdb.connect(**config)
|
||||||
|
|
Loading…
Reference in a new issue