summaryrefslogtreecommitdiff
path: root/lib/ansible/runner
diff options
context:
space:
mode:
authorJan-Piet Mens <jpmens@gmail.com>2012-11-10 16:16:03 +0100
committerJan-Piet Mens <jpmens@gmail.com>2012-11-10 17:50:21 +0100
commitbd55899a6079181ee5e91502a1195b476939c696 (patch)
treebf7c64935a021e959a06ece4bf3487d1d169ca29 /lib/ansible/runner
parent38d9dc8bffd053d06a0b39f79fa40e8c23cc1195 (diff)
downloadansible-bd55899a6079181ee5e91502a1195b476939c696.tar.gz
$LOOKUP(dnstxt): handle exceptions
de-spaced
Diffstat (limited to 'lib/ansible/runner')
-rw-r--r--lib/ansible/runner/lookup_plugins/dnstxt.py17
1 files changed, 13 insertions, 4 deletions
diff --git a/lib/ansible/runner/lookup_plugins/dnstxt.py b/lib/ansible/runner/lookup_plugins/dnstxt.py
index a26fa28f82..819f9b90a6 100644
--- a/lib/ansible/runner/lookup_plugins/dnstxt.py
+++ b/lib/ansible/runner/lookup_plugins/dnstxt.py
@@ -20,6 +20,7 @@ import os
HAVE_DNS=False
try:
import dns.resolver
+ from dns.exception import DNSException
HAVE_DNS=True
except ImportError:
pass
@@ -43,9 +44,17 @@ class LookupModule(object):
domain = terms.split()[0]
string = []
- answers = dns.resolver.query(domain, 'TXT')
- for rdata in answers:
- s = rdata.to_text()
- string.append(s[1:-1]) # Strip outside quotes on TXT rdata
+ try:
+ answers = dns.resolver.query(domain, 'TXT')
+ for rdata in answers:
+ s = rdata.to_text()
+ string.append(s[1:-1]) # Strip outside quotes on TXT rdata
+
+ except dns.resolver.NXDOMAIN:
+ string = 'NXDOMAIN'
+ except dns.resolver.Timeout:
+ string = ''
+ except dns.exception.DNSException as e:
+ raise errors.AnsibleError("dns.resolver unhandled exception", e)
return ''.join(string)