# DNS lookup not working

**URL:** <https://forum.ansible.com/t/dns-lookup-not-working/28433>\
**Category:** Ansible Project\
**Created:** [August 27, 2018, 9:49pm UTC](https://forum.ansible.com/t/dns-lookup-not-working/28433 "2018-08-27T21:49:34Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![Guy\_Knights](https://avatars.discourse-cdn.com/v4/letter/g/db5fbb/32.png) [@Guy\_Knights](https://forum.ansible.com/u/Guy_Knights)\
**Post date:** [August 27, 2018, 9:49pm UTC](https://forum.ansible.com/t/dns-lookup-not-working/28433/1 "2018-08-27T21:49:34Z")

</div>

I have a task that uses the dig lookup to resolve a DNS record, but it fails with the error, “An unhandled exception occurred while running the lookup plugin ‘dig’. Error was a \<class ‘ansible.errors.AnsibleError’\>, original message: The dig lookup requires the python ‘dnspython’ library and it is not installed”.

However, the dnspython library is definitely installed on the host. Here’s the task definition:

- blockinfile:  
dest: ~/.ssh/config  
marker: “# {mark} ANSIBLE MANAGED BLOCK - SVN MIRROR”  
block: |  
Host XXXXXXXXXX  
HostName {{ lookup(‘dig’, ‘YYYYYYYYYYYY’) }}  
User XXXXXXX  
Port 22  
IdentityFile ~/.ssh/svn\_key  
IdentitiesOnly yes  
RSAAuthentication yes  
StrictHostKeyChecking no  
create: yes

Here’s the output of pip freeze on the host where the task fails:

Cheetah==2.4.4  
Landscape-Client==14.12  
PAM==0.4.2  
PyYAML==3.13  
Twisted-Core==13.2.0  
Twisted-Names==13.2.0  
Twisted-Web==13.2.0  
apt-xapian-index==0.45  
argparse==1.2.1  
awscli==1.16.1  
backports.ssl-match-hostname==3.5.0.1  
boto==2.49.0  
boto3==1.8.1  
botocore==1.11.1  
certifi==2018.8.13  
chardet==3.0.4  
cloud-init==0.7.5  
colorama==0.3.9  
configobj==4.7.2  
dnspython==1.15.0  
docker-py==1.9.0  
docutils==0.14  
futures==3.2.0  
html5lib==0.999  
httplib2==0.8  
idna==2.7  
iotop==0.6  
ipaddress==1.0.22  
jmespath==0.9.3  
jsonpatch==1.3  
jsonpointer==1.0  
oauth==1.0.1  
prettytable==0.7.2  
pyOpenSSL==0.13  
pyasn1==0.4.4  
pycurl==7.19.3  
pyserial==2.6  
python-apt==0.9.3.5ubuntu3  
python-dateutil==2.7.3  
python-debian==0.1.21-nmu2ubuntu2  
requests==2.19.1  
rsa==3.4.2  
s3transfer==0.1.13  
six==1.11.0  
ssh-import-id==3.21  
urllib3==1.23  
virtualenv==16.0.0  
websocket-client==0.49.0  
wheel==0.24.0  
wsgiref==0.1.2  
zope.interface==4.0.5

Any idea why it fails?

Thanks,  
Guy

---

<div class="post-metadata">

**Author:** ![Kai\_Stian\_Olstad](https://avatars.discourse-cdn.com/v4/letter/k/e19adc/32.png) [@Kai\_Stian\_Olstad](https://forum.ansible.com/u/Kai_Stian_Olstad)\
**Post date:** [August 27, 2018, 9:53pm UTC](https://forum.ansible.com/t/dns-lookup-not-working/28433/2 "2018-08-27T21:53:20Z")

</div>

lookup plugins run on localhost aka Ansible controller not the remote host.

---

<div class="post-metadata">

**Author:** ![Jonathan\_Lozada\_De\_L](https://avatars.discourse-cdn.com/v4/letter/j/eb8c5e/32.png) [@Jonathan\_Lozada\_De\_L](https://forum.ansible.com/u/Jonathan_Lozada_De_L)\
**Post date:** [August 27, 2018, 10:07pm UTC](https://forum.ansible.com/t/dns-lookup-not-working/28433/3 "2018-08-27T22:07:31Z")

</div>

agreed. So you need to add connection: local or delegate\_to

---

<div class="post-metadata">

**Author:** ![Kai\_Stian\_Olstad](https://avatars.discourse-cdn.com/v4/letter/k/e19adc/32.png) [@Kai\_Stian\_Olstad](https://forum.ansible.com/u/Kai_Stian_Olstad)\
**Post date:** [August 27, 2018, 10:32pm UTC](https://forum.ansible.com/t/dns-lookup-not-working/28433/4 "2018-08-27T22:32:04Z")

</div>

That wont work.  
The block in file is needed on the remote host, and that is fine.  
Since lookup plugins run on localhost, dnspython is needed on Ansible controller not the remote host.

If DNS lookup has to be done on the remote host a command/shell module with dig or some other DNS utilities is required.

---

<div class="post-metadata">

**Author:** ![Guy\_Knights](https://avatars.discourse-cdn.com/v4/letter/g/db5fbb/32.png) [@Guy\_Knights](https://forum.ansible.com/u/Guy_Knights)\
**Post date:** [August 27, 2018, 11:05pm UTC](https://forum.ansible.com/t/dns-lookup-not-working/28433/5 "2018-08-27T23:05:29Z")

</div>

Ahh, right I guess didn’t properly read that very first paragraph on the lookups documentation page! Ok, thanks for info everyone.

Cheers,  
Guy
