From d2d1b44d5ce5b3c74686c982e9629a7c2c0d686e Mon Sep 17 00:00:00 2001 From: Mark Chappell Date: Thu, 27 Aug 2020 16:45:20 +0200 Subject: [PATCH] Partial backport of 60552 to fix ansible-collections/community.aws/198 (#71416) --- .../fragments/60552-aws_acm_info-failed.yml | 2 ++ lib/ansible/modules/cloud/amazon/aws_acm_info.py | 15 ++++++++------- 2 files changed, 10 insertions(+), 7 deletions(-) create mode 100644 changelogs/fragments/60552-aws_acm_info-failed.yml diff --git a/changelogs/fragments/60552-aws_acm_info-failed.yml b/changelogs/fragments/60552-aws_acm_info-failed.yml new file mode 100644 index 00000000000..0a8d244a58a --- /dev/null +++ b/changelogs/fragments/60552-aws_acm_info-failed.yml @@ -0,0 +1,2 @@ +bugfixes: +- aws_acm_info - fix `KeyError` failure when retrieving keys with a `Failed` status (https://github.com/ansible-collections/community.aws/issues/198) diff --git a/lib/ansible/modules/cloud/amazon/aws_acm_info.py b/lib/ansible/modules/cloud/amazon/aws_acm_info.py index fe56e6c9677..aa209ff79cb 100644 --- a/lib/ansible/modules/cloud/amazon/aws_acm_info.py +++ b/lib/ansible/modules/cloud/amazon/aws_acm_info.py @@ -287,13 +287,14 @@ def get_certificates(client, module, domain_name=None, statuses=None): module.fail_json(msg="Couldn't obtain certificate metadata for domain %s" % certificate['DomainName'], exception=traceback.format_exc(), **camel_dict_to_snake_dict(e.response)) - try: - cert_data.update(get_certificate_with_backoff(client, certificate['CertificateArn'])) - except botocore.exceptions.ClientError as e: - if e.response['Error']['Code'] != "RequestInProgressException": - module.fail_json(msg="Couldn't obtain certificate data for domain %s" % certificate['DomainName'], - exception=traceback.format_exc(), - **camel_dict_to_snake_dict(e.response)) + if cert_data['Status'] not in ['PENDING_VALIDATION', 'VALIDATION_TIMED_OUT', 'FAILED']: + try: + cert_data.update(get_certificate_with_backoff(client, certificate['CertificateArn'])) + except botocore.exceptions.ClientError as e: + if e.response['Error']['Code'] != "RequestInProgressException": + module.fail_json(msg="Couldn't obtain certificate data for domain %s" % certificate['DomainName'], + exception=traceback.format_exc(), + **camel_dict_to_snake_dict(e.response)) cert_data = camel_dict_to_snake_dict(cert_data) try: tags = list_certificate_tags_with_backoff(client, certificate['CertificateArn'])