Recently I was working on writing some quick Openstack and VMware deployment workflows. I wrote a DNS Check playbook to do a quick DNS lookup that would fail if the requested hostname already existed in DNS. This playbook runs on the ansible host and uses the lookup plugin to perform a dig on the passed in hostname.
---
- name: check dns records
hosts: localhost
connection: local
vars:
host_name: host
domain: example.com
tasks:
- set_fact:
fqdn: "{{ host_name }}.{{ domain }}"
- set_fact:
dns_lookup: "{{ lookup('dig', fqdn) }}"
failed_when: dns_lookup != "NXDOMAIN"