-
Notifications
You must be signed in to change notification settings - Fork 1.6k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
dig + wantlist can return a list with an empty string instead of an empty list #5428
Comments
Files identified in the description: If these files are incorrect, please update the |
This is "as designed" (https://github.com/ansible-collections/community.general/blob/main/plugins/lookup/dig.py#L382), and I don't see a place in the documentation which says that this won't be the case, so I guess it's not a bug. It is definitely nothing I would expect as a user, I fully agree on that. (I would guess this is a leftover from the times when |
I do not recall why that's there or even if I originally put that there so I tend to agree with @felixfontein that it's not a bug... @RomainMou what happens when you use |
I have the same result with
|
Thank you. I consider this a bug, and if @felixfontein agrees I will attempt to address this and fix. |
I'm a bit worried about this, this behavior has been the case for many years now, and I'm very sure there are hundreds of playbooks and roles that assume that the lookup will return I think the only clean way to fix this is to 1) add a new option which controls this behavior with default = current behavior, 2) deprecate the current default, 3) once the deprecation expires (should be in a long enough time in the future) switch the default. This is annoying and quite some extra effort, but just changing the behavior will likely break too many playbooks and roles. |
Hundreds of playbooks that use the |
As stated in Ansible documentation about collection versioning:
This modification could broke some workflows. So I guess @felixfontein is right about a depreciation warning until the next major version of the collection. But I think it should be eventually fixed. I only tested |
@RomainMou also see the paragraph on "Deprecation" in #582. We'd have to wait more than for the next major release with changing the default. |
Because the plugin doesn't print its authors list every time it's used ;-) |
How do you gentlemen like this, using a boolean flag
|
diff --git plugins/lookup/dig.py plugins/lookup/dig.py
index d7a7d8ec..847c2c77 100644
--- plugins/lookup/dig.py
+++ plugins/lookup/dig.py
@@ -52,6 +52,13 @@ DOCUMENTATION = '''
default: false
type: bool
version_added: 5.4.0
+ real_empty:
+ description:
+ - Return empty result without empty strings
+ - The default for this option will likely change to C(true) in the future.
+ default: false
+ type: bool
+ version_added: 4.8.1
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.
@@ -285,6 +292,7 @@ class LookupModule(LookupBase):
qtype = 'A'
flat = True
fail_on_error = False
+ real_empty = False
rdclass = dns.rdataclass.from_text('IN')
for t in terms:
@@ -325,6 +333,8 @@ class LookupModule(LookupBase):
myres.retry_servfail = boolean(arg)
elif opt == 'fail_on_error':
fail_on_error = boolean(arg)
+ elif opt == 'real_empty':
+ real_empty = boolean(arg)
continue
@@ -375,15 +385,18 @@ class LookupModule(LookupBase):
except dns.resolver.NXDOMAIN as err:
if fail_on_error:
raise AnsibleError("Lookup failed: %s" % str(err))
- ret.append('NXDOMAIN')
+ if not real_empty:
+ ret.append('NXDOMAIN')
except dns.resolver.NoAnswer as err:
if fail_on_error:
raise AnsibleError("Lookup failed: %s" % str(err))
- ret.append("")
+ if not real_empty:
+ ret.append("")
except dns.resolver.Timeout as err:
if fail_on_error:
raise AnsibleError("Lookup failed: %s" % str(err))
- ret.append('')
+ if not real_empty:
+ ret.append("")
except dns.exception.DNSException as err:
raise AnsibleError("dns.resolver unhandled exception %s" % to_native(err)) |
@jpmens looks good. The description needs to be updated to also mention that it will return an empty list instead of |
Thank you for your guidance, Felix. Will prepare PR.
|
#5457 implements the same for dnstxt. |
Summary
When I use the lookup plugin
community.general.dig
withwantlist=true
and there is no record, the plugin return[""]
instead of[]
.community.general.dnstxt
has the same issue.Issue Type
Bug Report
Component Name
dig
Ansible Version
Community.general Version
Configuration
OS / Environment
No response
Steps to Reproduce
Expected Results
TASK [Print retrieve NS] ****************************************************************************************************************************************************************************
ok: [localhost] => {
"ns": []
}
Actual Results
Code of Conduct
The text was updated successfully, but these errors were encountered: