-
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 lookup: Allow to pass port for DNS lookup #8966
dig lookup: Allow to pass port for DNS lookup #8966
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for your contribution!
@@ -0,0 +1,4 @@ | |||
--- | |||
minor_changes: | |||
- dig lookup module - add ``port`` option to specify DNS server port (https://github.com/ansible-collections/community.general/pull/8966). |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
- dig lookup module - add ``port`` option to specify DNS server port (https://github.com/ansible-collections/community.general/pull/8966). | |
- dig lookup plugin - add ``port`` option to specify DNS server port (https://github.com/ansible-collections/community.general/pull/8966). |
plugins/lookup/dig.py
Outdated
@@ -358,7 +363,6 @@ def run(self, terms, variables=None, **kwargs): | |||
nameservers.append(nsaddr) | |||
except Exception as e: | |||
raise AnsibleError("dns lookup NS: %s" % to_native(e)) | |||
myres.nameservers = nameservers |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The old code only keeps the nameservers from the last entry in @
, while with your change all nameservers provided by the user are used.
I would say this is a bugfix. (Or is myres.nameservers = ...
doing some magic so that if you do it twice, the list of nameservers is extended?)
Do you mind moving the nameserver modification to a separate PR? Bugfixes are backported to more stable branches than new features (which adding port
is).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I didn't even notice there was a bug and my change fixed it. Thanks for pointing that out. I'll open another PR for just that bugfix.
plugins/lookup/dig.py
Outdated
elif opt == 'port': | ||
port = int(arg) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This processing is only for legacy argument parsing.
elif opt == 'port': | |
port = int(arg) |
Thanks for your review! I've applied the suggested changes |
Created separate PR with just the multi-nameservers-bugfix as #8970 |
This will likely need a rebase to resolve the conflict once #8970 has been merged. |
This now needs a rebase. |
dnspython accepts a port as part of the nameserver. Currently, the nameservers are passed as strings which leads dnspython to create Nameserver objects out of them using the port that is currently set in the Resolver instance. That creation of Nameserver objects is done right when the `nameservers` property is set. If a port is to be set by us, the `port` attribute of the Resolver needs to be set before the nameservers are passed to the Resolver so when the nameservers are passed, that new port is used to create the Nameserver objects. Therefore, the assignment of the `nameservers` property of the Resolver is moved after the argument processing so the `port` attribute is (if it's given in the lookup-call) definitely set before the `nameservers` property.
fe59150
to
a830110
Compare
Rebased |
Backport to stable-9: 💚 backport PR created✅ Backport PR branch: Backported as #9004 🤖 @patchback |
dnspython accepts a port as part of the nameserver. Currently, the nameservers are passed as strings which leads dnspython to create Nameserver objects out of them using the port that is currently set in the Resolver instance. That creation of Nameserver objects is done right when the `nameservers` property is set. If a port is to be set by us, the `port` attribute of the Resolver needs to be set before the nameservers are passed to the Resolver so when the nameservers are passed, that new port is used to create the Nameserver objects. Therefore, the assignment of the `nameservers` property of the Resolver is moved after the argument processing so the `port` attribute is (if it's given in the lookup-call) definitely set before the `nameservers` property. (cherry picked from commit 5e6b8e5)
@JaegerMaKn thanks for your contribution! |
… for DNS lookup (#9004) dig lookup: Allow to pass port for DNS lookup (#8966) dnspython accepts a port as part of the nameserver. Currently, the nameservers are passed as strings which leads dnspython to create Nameserver objects out of them using the port that is currently set in the Resolver instance. That creation of Nameserver objects is done right when the `nameservers` property is set. If a port is to be set by us, the `port` attribute of the Resolver needs to be set before the nameservers are passed to the Resolver so when the nameservers are passed, that new port is used to create the Nameserver objects. Therefore, the assignment of the `nameservers` property of the Resolver is moved after the argument processing so the `port` attribute is (if it's given in the lookup-call) definitely set before the `nameservers` property. (cherry picked from commit 5e6b8e5) Co-authored-by: JaegerMaKn <[email protected]>
SUMMARY
Add new option
port
to thedig
lookup module to specify which port is to be used for DNS query.This is necessary for setups in which a (custom/internal) DNS server listens on a non-default port.
ISSUE TYPE
COMPONENT NAME
dig
ADDITIONAL INFORMATION
dnspython accepts a port as part of the nameserver and not, like the other optioins that are currently present in the
dig
module, to be passed to thequery
function.Currently, the nameservers are passed as strings which leads dnspython to create Nameserver objects out of them using the port that is currently set in the Resolver instance. That creation of Nameserver objects is done right when the
nameservers
property is set.If a port is to be set by us, the
port
attribute of the Resolver needs to be set before the nameservers are passed to the Resolver so when the nameservers are passed, that new port is used to create the Nameserver objects.Therefore, the assignment of the
nameservers
property of the Resolver is moved after the argument processing so theport
attribute is (if it's given) definitely set before thenameservers
property.