diff options
author | Serge van Ginderachter <serge@vanginderachter.be> | 2016-08-04 17:27:39 +0200 |
---|---|---|
committer | Toshio Kuratomi <a.badger@gmail.com> | 2016-08-04 08:27:39 -0700 |
commit | fc764553260e02bb7b36bf7c601685206d6f93cf (patch) | |
tree | 6979cd89c1e062ef7344149a8d333ff43c891acb | |
parent | 9a47088d672ce4bcd423aa74f1d433a690f5688f (diff) | |
download | ansible-modules-extras-fc764553260e02bb7b36bf7c601685206d6f93cf.tar.gz |
return a proper result set for getmaster/getslave (#2595)
* return a proper result set for getmaster/getslave
when not on a master/slave.
This allows for a cleaner error handling.
* A more uniform return of result keys for getmaster/slave
-rw-r--r-- | database/mysql/mysql_replication.py | 22 |
1 files changed, 12 insertions, 10 deletions
diff --git a/database/mysql/mysql_replication.py b/database/mysql/mysql_replication.py index b9a7d13c..8bc964cf 100644 --- a/database/mysql/mysql_replication.py +++ b/database/mysql/mysql_replication.py @@ -258,18 +258,20 @@ def main(): module.fail_json(msg="unable to find %s. Exception message: %s" % (config_file, e)) if mode in "getmaster": - masterstatus = get_master_status(cursor) - try: - module.exit_json( **masterstatus ) - except TypeError: - module.fail_json(msg="Server is not configured as mysql master") + status = get_master_status(cursor) + if not isinstance(status, dict): + status = dict(Is_Master=False, msg="Server is not configured as mysql master") + else: + status['Is_Master'] = True + module.exit_json(**status) elif mode in "getslave": - slavestatus = get_slave_status(cursor) - try: - module.exit_json( **slavestatus ) - except TypeError, e: - module.fail_json(msg="Server is not configured as mysql slave. ERROR: %s" % e) + status = get_slave_status(cursor) + if not isinstance(status, dict): + status = dict(Is_Slave=False, msg="Server is not configured as mysql slave") + else: + status['Is_Slave'] = True + module.exit_json(**status) elif mode in "changemaster": chm=[] |