Skip to content

Commit

Permalink
nsupdate: fix 'index out of range' error when no TTL answer is given (#…
Browse files Browse the repository at this point in the history
…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
  • Loading branch information
silkeh authored Sep 10, 2023
1 parent afeeb89 commit 208df2c
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 4 deletions.
2 changes: 2 additions & 0 deletions changelogs/fragments/7219-fix-nsupdate-cname.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
bugfixes:
- nsupdate - fix a possible ``list index out of range`` exception (https://github.com/ansible-collections/community.general/issues/836).
6 changes: 2 additions & 4 deletions plugins/modules/nsupdate.py
Original file line number Diff line number Diff line change
Expand Up @@ -467,10 +467,8 @@ def ttl_changed(self):
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']


Expand Down

0 comments on commit 208df2c

Please sign in to comment.