From 58c8696fc5c1403a7025a319695e275f8fece7c7 Mon Sep 17 00:00:00 2001 From: Toshio Kuratomi Date: Thu, 30 Apr 2015 12:49:32 -0700 Subject: [PATCH] Allow playbook specified login_user and login_password to override config file settings --- database/mysql/mysql_user.py | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/database/mysql/mysql_user.py b/database/mysql/mysql_user.py index cf9293d0c19..1888cc854ec 100644 --- a/database/mysql/mysql_user.py +++ b/database/mysql/mysql_user.py @@ -182,7 +182,7 @@ class InvalidPrivsError(Exception): # 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 = { 'host': module.params['login_host'], 'db': 'mysql' @@ -195,10 +195,14 @@ def connect(module, login_user, login_password, config_file='~/.my.cnf'): if os.path.exists(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 + if login_password is not None: config['passwd'] = login_password - + db_connection = MySQLdb.connect(**config) return db_connection.cursor()