From ad8965218d820f842e84b856d4de5ae7111645e3 Mon Sep 17 00:00:00 2001 From: Jonathan Lung Date: Sat, 20 Aug 2022 07:22:13 -0400 Subject: [PATCH] Fix nsupdate when updating NS record (#5112) * Fix nsupdate when updating NS record * Changelog fragment * Update changelogs/fragments/5112-fix-nsupdate-ns-entry.yaml Co-authored-by: Felix Fontein * Switch to fallback to AUTHORITY instead of using with NS type. * Update plugins/modules/net_tools/nsupdate.py Co-authored-by: Felix Fontein * Update plugins/modules/net_tools/nsupdate.py Co-authored-by: Felix Fontein Co-authored-by: jonathan lung Co-authored-by: Felix Fontein --- changelogs/fragments/5112-fix-nsupdate-ns-entry.yaml | 2 ++ plugins/modules/net_tools/nsupdate.py | 5 ++++- 2 files changed, 6 insertions(+), 1 deletion(-) create mode 100644 changelogs/fragments/5112-fix-nsupdate-ns-entry.yaml diff --git a/changelogs/fragments/5112-fix-nsupdate-ns-entry.yaml b/changelogs/fragments/5112-fix-nsupdate-ns-entry.yaml new file mode 100644 index 0000000000..c5f8653fd6 --- /dev/null +++ b/changelogs/fragments/5112-fix-nsupdate-ns-entry.yaml @@ -0,0 +1,2 @@ +bugfixes: + - nsupdate - compatibility with NS records (https://github.com/ansible-collections/community.general/pull/5112). diff --git a/plugins/modules/net_tools/nsupdate.py b/plugins/modules/net_tools/nsupdate.py index 9f29d4b5fd..512e44da2f 100644 --- a/plugins/modules/net_tools/nsupdate.py +++ b/plugins/modules/net_tools/nsupdate.py @@ -427,7 +427,10 @@ class RecordManager(object): if lookup.rcode() != dns.rcode.NOERROR: self.module.fail_json(msg='Failed to lookup TTL of existing matching record.') - current_ttl = lookup.answer[0].ttl + 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 return current_ttl != self.module.params['ttl']