From 9d250e89809a5918bebaa7e738fcf8252d10bd99 Mon Sep 17 00:00:00 2001 From: Simon Stone Date: Tue, 2 Jun 2020 09:50:21 +0100 Subject: [PATCH] Handle HTTP 404 Not Found errors when state == absent (resolves #253) Signed-off-by: Simon Stone --- plugins/modules/certificate_authority.py | 5 ++++- plugins/modules/external_ordering_service.py | 2 +- plugins/modules/peer.py | 5 ++++- 3 files changed, 9 insertions(+), 3 deletions(-) diff --git a/plugins/modules/certificate_authority.py b/plugins/modules/certificate_authority.py index 39171d3a..cd7f38fa 100644 --- a/plugins/modules/certificate_authority.py +++ b/plugins/modules/certificate_authority.py @@ -295,7 +295,10 @@ def main(): if state == 'absent' and certificate_authority_exists: # The certificate authority should not exist, so delete it. - console.delete_ca(certificate_authority['id']) + if certificate_authority_corrupt: + console.delete_ext_ca(certificate_authority['id']) + else: + console.delete_ca(certificate_authority['id']) return module.exit_json(changed=True) elif state == 'absent': diff --git a/plugins/modules/external_ordering_service.py b/plugins/modules/external_ordering_service.py index 342e7d1f..4948badb 100644 --- a/plugins/modules/external_ordering_service.py +++ b/plugins/modules/external_ordering_service.py @@ -275,7 +275,7 @@ def main(): has_deployment_attrs = False has_location = False for ordering_service_node in existing_ordering_service: - if not ordering_service_node.get('deployment_attrs_missing', False): + if 'deployment_attrs_missing' not in ordering_service_node: has_deployment_attrs = True break elif ordering_service_node.get('location', '-') != '-': diff --git a/plugins/modules/peer.py b/plugins/modules/peer.py index 64062b96..c96b3f27 100644 --- a/plugins/modules/peer.py +++ b/plugins/modules/peer.py @@ -504,7 +504,10 @@ def main(): if state == 'absent' and peer_exists: # The peer should not exist, so delete it. - console.delete_peer(peer['id']) + if peer_corrupt: + console.delete_ext_peer(peer['id']) + else: + console.delete_peer(peer['id']) return module.exit_json(changed=True) elif state == 'absent':