Skip to content

Commit

Permalink
Add TCP option for dig plugin. (#7343)
Browse files Browse the repository at this point in the history
* Add TCP option for dig plugin.

* Add changelog of dig tcp option

* Apply suggestions from code review

Co-authored-by: Felix Fontein <[email protected]>

---------

Co-authored-by: s-miyachi <[email protected]>
Co-authored-by: Felix Fontein <[email protected]>
  • Loading branch information
3 people authored Oct 4, 2023
1 parent 39895a6 commit cda6fc9
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 1 deletion.
2 changes: 2 additions & 0 deletions changelogs/fragments/7343-dig-tcp-option.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
minor_changes:
- dig lookup plugin - add TCP option to enable the use of TCP connection during DNS lookup (https://github.com/ansible-collections/community.general/pull/7343).
10 changes: 9 additions & 1 deletion plugins/lookup/dig.py
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,11 @@
- "Class."
type: str
default: 'IN'
tcp:
description: Use TCP to lookup DNS records.
default: false
type: bool
version_added: 7.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.
Expand Down Expand Up @@ -329,6 +334,7 @@ def run(self, terms, variables=None, **kwargs):
flat = self.get_option('flat')
fail_on_error = self.get_option('fail_on_error')
real_empty = self.get_option('real_empty')
tcp = self.get_option('tcp')
try:
rdclass = dns.rdataclass.from_text(self.get_option('class'))
except Exception as e:
Expand Down Expand Up @@ -375,6 +381,8 @@ def run(self, terms, variables=None, **kwargs):
fail_on_error = boolean(arg)
elif opt == 'real_empty':
real_empty = boolean(arg)
elif opt == 'tcp':
tcp = boolean(arg)

continue

Expand Down Expand Up @@ -408,7 +416,7 @@ def run(self, terms, variables=None, **kwargs):

for domain in domains:
try:
answers = myres.query(domain, qtype, rdclass=rdclass)
answers = myres.query(domain, qtype, rdclass=rdclass, tcp=tcp)
for rdata in answers:
s = rdata.to_text()
if qtype.upper() == 'TXT':
Expand Down

0 comments on commit cda6fc9

Please sign in to comment.