From ea104884ec23c2ff45819c3bad07a72ff291ee6a Mon Sep 17 00:00:00 2001 From: "patchback[bot]" <45432694+patchback[bot]@users.noreply.github.com> Date: Fri, 1 Sep 2023 12:43:21 +0000 Subject: [PATCH] opensearch: avoid a KeyError during the DomainConfig reading (#1910) (#1923) [PR #1910/9a9c8c58 backport][stable-6] opensearch: avoid a KeyError during the DomainConfig reading This is a backport of PR #1910 as merged into main (9a9c8c5). 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: Alina Buzachis --- 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: