Skip to content

Commit

Permalink
Don't return module error when mysql_connect fails (ansible#64560)
Browse files Browse the repository at this point in the history
mysql_user expects an Exception when using check_implicit_admin.
  • Loading branch information
juergenhoetzel committed Dec 4, 2019
1 parent b51a1bc commit 5224a05
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 8 deletions.
6 changes: 1 addition & 5 deletions lib/ansible/module_utils/mysql.py
Original file line number Diff line number Diff line change
Expand Up @@ -78,11 +78,7 @@ def mysql_connect(module, login_user=None, login_password=None, config_file='',
if connect_timeout is not None:
config['connect_timeout'] = connect_timeout

try:
db_connection = mysql_driver.connect(**config)

except Exception as e:
module.fail_json(msg="unable to connect to database: %s" % to_native(e))
db_connection = mysql_driver.connect(**config)

if cursor_class == 'DictCursor':
return db_connection.cursor(**{_mysql_cursor_param: mysql_driver.cursors.DictCursor})
Expand Down
10 changes: 7 additions & 3 deletions lib/ansible/modules/database/mysql/mysql_info.py
Original file line number Diff line number Diff line change
Expand Up @@ -452,9 +452,13 @@ def main():
if mysql_driver is None:
module.fail_json(msg=mysql_driver_fail_msg)

cursor = mysql_connect(module, login_user, login_password,
config_file, ssl_cert, ssl_key, ssl_ca, db,
connect_timeout=connect_timeout, cursor_class='DictCursor')
try:
cursor = mysql_connect(module, login_user, login_password,
config_file, ssl_cert, ssl_key, ssl_ca, db,
connect_timeout=connect_timeout, cursor_class='DictCursor')
except Exception as e:
module.fail_json(msg="unable to connect to database, check login_user and login_password are correct or %s has the credentials. "
"Exception message: %s" % (config_file, to_native(e)))

###############################
# Create object and do main job
Expand Down

0 comments on commit 5224a05

Please sign in to comment.