From 67f71842348fc8429192dd402a74467dc2c2d957 Mon Sep 17 00:00:00 2001 From: "patchback[bot]" <45432694+patchback[bot]@users.noreply.github.com> Date: Sun, 22 Aug 2021 11:58:37 +0200 Subject: [PATCH] Add option for retry_servfail (#3247) (#3251) * Add option for retry_servfail cf. https://dnspython.readthedocs.io/en/latest/resolver-class.html#dns.resolver.Resolver.retry_servfail Setting this option to `True` allows for the possibility of the lookup plugin to retry and thereby recover from potentially transient lookup failures, which would otherwise cause the task or play to bail with an unrecoverable exception. * Create 3247-retry_servfail-for-dig * documentation for `retry_servfail` option * Rename 3247-retry_servfail-for-dig to 3247-retry_servfail-for-dig.yaml * fix whitespace * Update plugins/lookup/dig.py Co-authored-by: Ajpantuso * Update plugins/lookup/dig.py Co-authored-by: Ajpantuso * rm try/except block Co-authored-by: Ajpantuso (cherry picked from commit 23e7ef025529b7c79fab284121f0b4b5045e45fa) Co-authored-by: Matt 'Archer' Vaughn --- changelogs/fragments/3247-retry_servfail-for-dig.yaml | 3 +++ plugins/lookup/dig.py | 11 +++++++++++ 2 files changed, 14 insertions(+) create mode 100644 changelogs/fragments/3247-retry_servfail-for-dig.yaml diff --git a/changelogs/fragments/3247-retry_servfail-for-dig.yaml b/changelogs/fragments/3247-retry_servfail-for-dig.yaml new file mode 100644 index 0000000000..1e4a00384f --- /dev/null +++ b/changelogs/fragments/3247-retry_servfail-for-dig.yaml @@ -0,0 +1,3 @@ +--- +minor_changes: + - dig lookup plugin - add ``retry_servfail`` option (https://github.com/ansible-collections/community.general/pull/3247). diff --git a/plugins/lookup/dig.py b/plugins/lookup/dig.py index f5156b4d1e..19ded61de7 100644 --- a/plugins/lookup/dig.py +++ b/plugins/lookup/dig.py @@ -35,6 +35,11 @@ DOCUMENTATION = ''' flat: description: If 0 each record is returned as a dictionary, otherwise a string default: 1 + retry_servfail: + description: Retry a nameserver if it returns SERVFAIL. + default: false + type: bool + version_added: 3.6.0 notes: - ALL is not a record per-se, merely the listed fields are available for any record results you retrieve in the form of a dictionary. - While the 'dig' lookup plugin supports anything which dnspython supports out of the box, only a subset can be converted into a dictionary. @@ -73,6 +78,10 @@ EXAMPLES = """ - ansible.builtin.debug: msg: "XMPP service for gmail.com. is available at {{ item.target }} on port {{ item.port }}" with_items: "{{ lookup('community.general.dig', '_xmpp-server._tcp.gmail.com./SRV', 'flat=0', wantlist=True) }}" + +- name: Retry nameservers that return SERVFAIL + ansible.builtin.debug: + msg: "{{ lookup('community.general.dig', 'example.org./A', 'retry_servfail=True') }}" """ RETURN = """ @@ -300,6 +309,8 @@ class LookupModule(LookupBase): rdclass = dns.rdataclass.from_text(arg) except Exception as e: raise AnsibleError("dns lookup illegal CLASS: %s" % to_native(e)) + elif opt == 'retry_servfail': + myres.retry_servfail = bool(arg) continue