1
0
Fork 0
mirror of https://github.com/ansible-collections/community.general.git synced 2024-09-14 20:13:21 +02:00

dnstxt lookup - add option to return empty list. (#5457)

This commit is contained in:
Felix Fontein 2022-11-01 22:19:33 +01:00 committed by GitHub
parent e718bd8445
commit 47cc2a4e8e
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 17 additions and 0 deletions

View file

@ -0,0 +1,2 @@
bugfixes:
- dnstxt 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/5457, https://github.com/ansible-collections/community.general/issues/5428).

View file

@ -20,6 +20,13 @@ DOCUMENTATION = '''
required: true required: true
type: list type: list
elements: string elements: string
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
''' '''
EXAMPLES = """ EXAMPLES = """
@ -76,6 +83,8 @@ class LookupModule(LookupBase):
if HAVE_DNS is False: if HAVE_DNS is False:
raise AnsibleError("Can't LOOKUP(dnstxt): module dns.resolver is not installed") raise AnsibleError("Can't LOOKUP(dnstxt): module dns.resolver is not installed")
real_empty = self.get_option('real_empty')
ret = [] ret = []
for term in terms: for term in terms:
domain = term.split()[0] domain = term.split()[0]
@ -87,10 +96,16 @@ class LookupModule(LookupBase):
string.append(s[1:-1]) # Strip outside quotes on TXT rdata string.append(s[1:-1]) # Strip outside quotes on TXT rdata
except dns.resolver.NXDOMAIN: except dns.resolver.NXDOMAIN:
if real_empty:
continue
string = 'NXDOMAIN' string = 'NXDOMAIN'
except dns.resolver.Timeout: except dns.resolver.Timeout:
if real_empty:
continue
string = '' string = ''
except dns.resolver.NoAnswer: except dns.resolver.NoAnswer:
if real_empty:
continue
string = '' string = ''
except DNSException as e: except DNSException as e:
raise AnsibleError("dns.resolver unhandled exception %s" % to_native(e)) raise AnsibleError("dns.resolver unhandled exception %s" % to_native(e))