Ansible DNS Check Playbook

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"

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s