From 38786fb0e21dc2f0a0d4acec2bb7d2b173687aa9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gon=C3=A9ri=20Le=20Bouder?= Date: Thu, 31 Aug 2023 14:06:58 -0400 Subject: [PATCH] opensearch: avoid a KeyError during the DomainConfig reading (#1910) opensearch: avoid a KeyError during the DomainConfig reading This commit avoids a KeyError exception in get_domain_config(). Some entries from DomainConfig don't have any Options key. For instance, ChangeProgressDetails. See: https://docs.aws.amazon.com/opensearch-service/latest/APIReference/API_DomainConfig.html https://docs.aws.amazon.com/opensearch-service/latest/APIReference/API_ChangeProgressDetails.html Closes: #1907 Reviewed-by: Markus Bergholz Reviewed-by: Alina Buzachis (cherry picked from commit 9a9c8c58b3120d3f1988030cf8a31662a992c335) --- changelogs/fragments/opensearch_domainconfig_no_options.yaml | 3 +++ plugins/module_utils/opensearch.py | 3 ++- 2 files changed, 5 insertions(+), 1 deletion(-) create mode 100644 changelogs/fragments/opensearch_domainconfig_no_options.yaml diff --git a/changelogs/fragments/opensearch_domainconfig_no_options.yaml b/changelogs/fragments/opensearch_domainconfig_no_options.yaml new file mode 100644 index 00000000000..d86d379f55d --- /dev/null +++ b/changelogs/fragments/opensearch_domainconfig_no_options.yaml @@ -0,0 +1,3 @@ +--- +bugfixes: +- "opensearch - Don't try to read a non existing key from the domain config (https://github.com/ansible-collections/community.aws/pull/1910)." diff --git a/plugins/module_utils/opensearch.py b/plugins/module_utils/opensearch.py index 2152a939827..173c8ba6edf 100644 --- a/plugins/module_utils/opensearch.py +++ b/plugins/module_utils/opensearch.py @@ -61,7 +61,8 @@ def get_domain_config(client, module, domain_name): arn = None if response is not None: for k in response["DomainConfig"]: - domain_config[k] = response["DomainConfig"][k]["Options"] + if "Options" in response["DomainConfig"][k]: + domain_config[k] = response["DomainConfig"][k]["Options"] domain_config["DomainName"] = domain_name # If ES cluster is attached to the Internet, the "VPCOptions" property is not present. if "VPCOptions" in domain_config: