DNS lookup not working

1,320 views
Skip to first unread message

Guy Knights

unread,
Aug 27, 2018, 5:49:35 PM8/27/18
to ansible...@googlegroups.com
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

Kai Stian Olstad

unread,
Aug 27, 2018, 5:53:33 PM8/27/18
to ansible...@googlegroups.com
On Monday, 27 August 2018 23.49.34 CEST Guy Knights wrote:
> 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:

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

--
Kai Stian Olstad


Jonathan Lozada De La Matta

unread,
Aug 27, 2018, 6:07:56 PM8/27/18
to ansible...@googlegroups.com
agreed. So you need to add connection: local or delegate_to

--
You received this message because you are subscribed to the Google Groups "Ansible Project" group.
To unsubscribe from this group and stop receiving emails from it, send an email to ansible-proje...@googlegroups.com.
To post to this group, send email to ansible...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/ansible-project/1913709.8AxLWYWHRC%40x1.
For more options, visit https://groups.google.com/d/optout.
--

Jonathan lozada de la matta

AUTOMATION CONSULTANT - AUTOMATION PRACTICE

Red Hat Consulting Services

jloz...@redhat.com   



 

Kai Stian Olstad

unread,
Aug 27, 2018, 6:32:15 PM8/27/18
to ansible...@googlegroups.com
On Tuesday, 28 August 2018 00.07.31 CEST Jonathan Lozada De La Matta wrote:
> agreed. So you need to add connection: local or delegate_to

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.


--
Kai Stian Olstad


Guy Knights

unread,
Aug 27, 2018, 7:05:29 PM8/27/18
to Ansible Project
Ahh, right I guess didn't properly read that very first paragraph on the lookups documentation page! Ok, thanks for info everyone.

Cheers,
Guy
Reply all
Reply to author
Forward
0 new messages