From 2a5e4b8a46ed5dd349c578a6dc15b134e24de7c8 Mon Sep 17 00:00:00 2001 From: "patchback[bot]" <45432694+patchback[bot]@users.noreply.github.com> Date: Mon, 11 Sep 2023 06:01:01 +0200 Subject: [PATCH] [PR #7219/208df2c9 backport][stable-6] nsupdate: fix 'index out of range' error when no TTL answer is given (#7235) nsupdate: fix 'index out of range' error when no TTL answer is given (#7219) * nsupdate: fix 'index out of range' error when no TTL answer is given Fix a possible `list index out of range` when no answer is returned in the `ttl_changed` method by applying the existing workaround for NS records to all record types. Resolves #836 * fixup! nsupdate: fix 'index out of range' error when no TTL answer is given (cherry picked from commit 208df2c9e6b7e0c0f6b5a7d8543e135a068c581f) Co-authored-by: Silke Hofstra --- changelogs/fragments/7219-fix-nsupdate-cname.yaml | 2 ++ plugins/modules/nsupdate.py | 6 ++---- 2 files changed, 4 insertions(+), 4 deletions(-) create mode 100644 changelogs/fragments/7219-fix-nsupdate-cname.yaml diff --git a/changelogs/fragments/7219-fix-nsupdate-cname.yaml b/changelogs/fragments/7219-fix-nsupdate-cname.yaml new file mode 100644 index 0000000000..bd58eb883f --- /dev/null +++ b/changelogs/fragments/7219-fix-nsupdate-cname.yaml @@ -0,0 +1,2 @@ +bugfixes: + - nsupdate - fix a possible ``list index out of range`` exception (https://github.com/ansible-collections/community.general/issues/836). diff --git a/plugins/modules/nsupdate.py b/plugins/modules/nsupdate.py index b2a84f76ba..74854163fe 100644 --- a/plugins/modules/nsupdate.py +++ b/plugins/modules/nsupdate.py @@ -467,10 +467,8 @@ class RecordManager(object): if lookup.rcode() != dns.rcode.NOERROR: self.module.fail_json(msg='Failed to lookup TTL of existing matching record.') - if self.module.params['type'] == 'NS': - current_ttl = lookup.answer[0].ttl if lookup.answer else lookup.authority[0].ttl - else: - current_ttl = lookup.answer[0].ttl + current_ttl = lookup.answer[0].ttl if lookup.answer else lookup.authority[0].ttl + return current_ttl != self.module.params['ttl']