From 121ef13e47a590a240c15d66586e1d4dd4f131c8 Mon Sep 17 00:00:00 2001 From: Serge van Ginderachter Date: Thu, 4 Aug 2016 17:17:10 +0200 Subject: [PATCH] Exception handling for MySQLdb warnings (#2594) Do not fail the module for warnings. Return warnings in the module result set. Fixes #719 Alternative to #720 and as discuseed over there. --- .../modules/extras/database/mysql/mysql_replication.py | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/lib/ansible/modules/extras/database/mysql/mysql_replication.py b/lib/ansible/modules/extras/database/mysql/mysql_replication.py index fde91499080..2306bd45ab9 100644 --- a/lib/ansible/modules/extras/database/mysql/mysql_replication.py +++ b/lib/ansible/modules/extras/database/mysql/mysql_replication.py @@ -274,6 +274,7 @@ def main(): elif mode in "changemaster": chm=[] chm_params = {} + result = {} if master_host: chm.append("MASTER_HOST=%(master_host)s") chm_params['master_host'] = master_host @@ -322,9 +323,12 @@ def main(): chm.append("MASTER_AUTO_POSITION = 1") try: changemaster(cursor, chm, chm_params) + except MySQLdb.Warning, e: + result['warning'] = str(e) except Exception, e: module.fail_json(msg='%s. Query == CHANGE MASTER TO %s' % (e, chm)) - module.exit_json(changed=True) + result['changed']=True + module.exit_json(**result) elif mode in "startslave": started = start_slave(cursor) if started is True: