# ansible check DNS against FQDN

**URL:** <https://forum.ansible.com/t/ansible-check-dns-against-fqdn/21669>\
**Category:** Ansible Project\
**Created:** [June 6, 2016, 4:08am UTC](https://forum.ansible.com/t/ansible-check-dns-against-fqdn/21669 "2016-06-06T04:08:22Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![John.1209](https://avatars.discourse-cdn.com/v4/letter/j/ecb155/32.png) [@John.1209](https://forum.ansible.com/u/John.1209)\
**Post date:** [June 6, 2016, 4:08am UTC](https://forum.ansible.com/t/ansible-check-dns-against-fqdn/21669/1 "2016-06-06T04:08:22Z")

</div>

I’m trying to come up with an ansible process to compare a DNS against an FQDN:

This is what I have:

---

<div class="post-metadata">

**Author:** ![Paul\_Totterman](https://avatars.discourse-cdn.com/v4/letter/p/3ec8ea/32.png) [@Paul\_Totterman](https://forum.ansible.com/u/Paul_Totterman)\
**Post date:** [June 6, 2016, 8:05am UTC](https://forum.ansible.com/t/ansible-check-dns-against-fqdn/21669/2 "2016-06-06T08:05:49Z")

</div>

> This is not working? Is there a better way to do this? Or please suggest a fix.

Consider using the dig-lookup: [https://docs.ansible.com/ansible/playbooks\_lookups.html#the-dns-lookup-dig](https://docs.ansible.com/ansible/playbooks_lookups.html#the-dns-lookup-dig)

Cheers,  
Paul

---

<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:** [June 6, 2016, 2:02pm UTC](https://forum.ansible.com/t/ansible-check-dns-against-fqdn/21669/3 "2016-06-06T14:02:03Z")

</div>

Your tasks: is misplaced and indentation is wrong, but this should work

- name: Set DNS variable  
&nbsp;&nbsp;&nbsp;command: dig {{ ansible\_fqdn }} +short  
&nbsp;&nbsp;&nbsp;register: DNSOUT

- name: Verify DNS  
&nbsp;&nbsp;&nbsp;command: echo not in DNS!  
&nbsp;&nbsp;&nbsp;when: DNSOUT.stdout == ""

The Verify DNS task won't show you anything on in the console, if that's what you are after you can do it like this

- debug: msg="{{ ansible\_fqdn }} not in DNS!"  
&nbsp;&nbsp;&nbsp;when: DNSOUT.stdout == ""
