[PR #8966/5e6b8e53 backport][stable-9] dig lookup: Allow to pass port 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 5e6b8e5327
)
Co-authored-by: JaegerMaKn <max.jaeger@knauf.com>
pull/9014/head
parent
154b5f86fd
commit
cc2794ad05
|
@ -0,0 +1,4 @@
|
|||
---
|
||||
minor_changes:
|
||||
- dig lookup plugin - add ``port`` option to specify DNS server port (https://github.com/ansible-collections/community.general/pull/8966).
|
||||
...
|
|
@ -75,6 +75,11 @@ DOCUMENTATION = '''
|
|||
default: false
|
||||
type: bool
|
||||
version_added: 7.5.0
|
||||
port:
|
||||
description: Use port as target port when looking up DNS records.
|
||||
default: 53
|
||||
type: int
|
||||
version_added: 9.5.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.
|
||||
|
@ -336,6 +341,7 @@ class LookupModule(LookupBase):
|
|||
fail_on_error = self.get_option('fail_on_error')
|
||||
real_empty = self.get_option('real_empty')
|
||||
tcp = self.get_option('tcp')
|
||||
port = self.get_option('port')
|
||||
try:
|
||||
rdclass = dns.rdataclass.from_text(self.get_option('class'))
|
||||
except Exception as e:
|
||||
|
@ -396,6 +402,8 @@ class LookupModule(LookupBase):
|
|||
|
||||
# print "--- domain = {0} qtype={1} rdclass={2}".format(domain, qtype, rdclass)
|
||||
|
||||
if port:
|
||||
myres.port = port
|
||||
if len(nameservers) > 0:
|
||||
myres.nameservers = nameservers
|
||||
|
||||
|
|
Loading…
Reference in New Issue