mirror of
https://github.com/ansible-collections/community.general.git
synced 2024-09-14 20:13:21 +02:00
add option to force dig lookup to return empty list instead of list of empty strings. (#5439)
fixes https://github.com/ansible-collections/community.general/issues/5428
This commit is contained in:
parent
fa924aae31
commit
df34a7b0f2
2 changed files with 18 additions and 3 deletions
2
changelogs/fragments/5439-dig-return-empty-result.yml
Normal file
2
changelogs/fragments/5439-dig-return-empty-result.yml
Normal file
|
@ -0,0 +1,2 @@
|
||||||
|
bugfixes:
|
||||||
|
- dig lookup plugin - add option to return empty result without empty strings, and return empty list instead of ``NXDOMAIN`` (https://github.com/ansible-collections/community.general/pull/5439, https://github.com/ansible-collections/community.general/issues/5428).
|
|
@ -52,6 +52,13 @@ DOCUMENTATION = '''
|
||||||
default: false
|
default: false
|
||||||
type: bool
|
type: bool
|
||||||
version_added: 5.4.0
|
version_added: 5.4.0
|
||||||
|
real_empty:
|
||||||
|
description:
|
||||||
|
- Return empty result without empty strings, and return empty list instead of C(NXDOMAIN).
|
||||||
|
- The default for this option will likely change to C(true) in the future.
|
||||||
|
default: false
|
||||||
|
type: bool
|
||||||
|
version_added: 6.0.0
|
||||||
notes:
|
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.
|
- 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.
|
- While the 'dig' lookup plugin supports anything which dnspython supports out of the box, only a subset can be converted into a dictionary.
|
||||||
|
@ -285,6 +292,7 @@ class LookupModule(LookupBase):
|
||||||
qtype = 'A'
|
qtype = 'A'
|
||||||
flat = True
|
flat = True
|
||||||
fail_on_error = False
|
fail_on_error = False
|
||||||
|
real_empty = False
|
||||||
rdclass = dns.rdataclass.from_text('IN')
|
rdclass = dns.rdataclass.from_text('IN')
|
||||||
|
|
||||||
for t in terms:
|
for t in terms:
|
||||||
|
@ -325,6 +333,8 @@ class LookupModule(LookupBase):
|
||||||
myres.retry_servfail = boolean(arg)
|
myres.retry_servfail = boolean(arg)
|
||||||
elif opt == 'fail_on_error':
|
elif opt == 'fail_on_error':
|
||||||
fail_on_error = boolean(arg)
|
fail_on_error = boolean(arg)
|
||||||
|
elif opt == 'real_empty':
|
||||||
|
real_empty = boolean(arg)
|
||||||
|
|
||||||
continue
|
continue
|
||||||
|
|
||||||
|
@ -375,15 +385,18 @@ class LookupModule(LookupBase):
|
||||||
except dns.resolver.NXDOMAIN as err:
|
except dns.resolver.NXDOMAIN as err:
|
||||||
if fail_on_error:
|
if fail_on_error:
|
||||||
raise AnsibleError("Lookup failed: %s" % str(err))
|
raise AnsibleError("Lookup failed: %s" % str(err))
|
||||||
ret.append('NXDOMAIN')
|
if not real_empty:
|
||||||
|
ret.append('NXDOMAIN')
|
||||||
except dns.resolver.NoAnswer as err:
|
except dns.resolver.NoAnswer as err:
|
||||||
if fail_on_error:
|
if fail_on_error:
|
||||||
raise AnsibleError("Lookup failed: %s" % str(err))
|
raise AnsibleError("Lookup failed: %s" % str(err))
|
||||||
ret.append("")
|
if not real_empty:
|
||||||
|
ret.append("")
|
||||||
except dns.resolver.Timeout as err:
|
except dns.resolver.Timeout as err:
|
||||||
if fail_on_error:
|
if fail_on_error:
|
||||||
raise AnsibleError("Lookup failed: %s" % str(err))
|
raise AnsibleError("Lookup failed: %s" % str(err))
|
||||||
ret.append('')
|
if not real_empty:
|
||||||
|
ret.append("")
|
||||||
except dns.exception.DNSException as err:
|
except dns.exception.DNSException as err:
|
||||||
raise AnsibleError("dns.resolver unhandled exception %s" % to_native(err))
|
raise AnsibleError("dns.resolver unhandled exception %s" % to_native(err))
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue