Skip to content

Commit

Permalink
Add option for retry_servfail (#3247)
Browse files Browse the repository at this point in the history
* 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 <ajpantuso@gmail.com>

* Update plugins/lookup/dig.py

Co-authored-by: Ajpantuso <ajpantuso@gmail.com>

* rm try/except block

Co-authored-by: Ajpantuso <ajpantuso@gmail.com>
  • Loading branch information
nethershaw and Ajpantuso authored Aug 21, 2021
1 parent 8a62b79 commit 23e7ef0
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 0 deletions.
3 changes: 3 additions & 0 deletions changelogs/fragments/3247-retry_servfail-for-dig.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
---
minor_changes:
- dig lookup plugin - add ``retry_servfail`` option (https://github.com/ansible-collections/community.general/pull/3247).
11 changes: 11 additions & 0 deletions plugins/lookup/dig.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,11 @@
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.
Expand Down Expand Up @@ -73,6 +78,10 @@
- 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 = """
Expand Down Expand Up @@ -300,6 +309,8 @@ def run(self, terms, variables=None, **kwargs):
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

Expand Down

0 comments on commit 23e7ef0

Please sign in to comment.