diff --git a/library/radosgw_zone.py b/library/radosgw_zone.py index 0e048f474..244520f60 100644 --- a/library/radosgw_zone.py +++ b/library/radosgw_zone.py @@ -16,6 +16,10 @@ from __future__ import absolute_import, division, print_function __metaclass__ = type from ansible.module_utils.basic import AnsibleModule +try: + from ansible.module_utils.ca_common import fatal +except ImportError: + from module_utils.ca_common import fatal import datetime import json import os @@ -412,24 +416,27 @@ def run_module(): if rc == 0: zone = json.loads(out) _rc, _cmd, _out, _err = exec_commands(module, get_zonegroup(module, container_image=container_image)) - zonegroup = json.loads(_out) - if not access_key: - access_key = '' - if not secret_key: - secret_key = '' - current = { - 'endpoints': next(zone['endpoints'] for zone in zonegroup['zones'] if zone['name'] == name), - 'access_key': zone['system_key']['access_key'], - 'secret_key': zone['system_key']['secret_key'] - } - asked = { - 'endpoints': endpoints, - 'access_key': access_key, - 'secret_key': secret_key - } - if current != asked: - rc, cmd, out, err = exec_commands(module, modify_zone(module, container_image=container_image)) - changed = True + if _rc == 0: + zonegroup = json.loads(_out) + if not access_key: + access_key = '' + if not secret_key: + secret_key = '' + current = { + 'endpoints': next(zone['endpoints'] for zone in zonegroup['zones'] if zone['name'] == name), + 'access_key': zone['system_key']['access_key'], + 'secret_key': zone['system_key']['secret_key'] + } + asked = { + 'endpoints': endpoints, + 'access_key': access_key, + 'secret_key': secret_key + } + if current != asked: + rc, cmd, out, err = exec_commands(module, modify_zone(module, container_image=container_image)) + changed = True + else: + fatal(_err, module) else: rc, cmd, out, err = exec_commands(module, create_zone(module, container_image=container_image)) changed = True