ansible check DNS against FQDN

2,496 views
Skip to first unread message

John.1209

unread,
Jun 6, 2016, 12:08:22 AM6/6/16
to Ansible Project
I'm trying to come up with an ansible process to compare a DNS against an FQDN:

This is what I have:

---
 - name: Set DNS variable
   shell: dig {{ ansible_fqdn }} +short
   register: DNSOUT

   tasks:
     - name: Verify DNS
#     - command: /usr/bin/echo {{ ansible_fqdn }} not in DNS!
       command: /usr/bin/echo not in DNS!
       when: $ansible_fqdn != DNSOUT

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

Paul Tötterman

unread,
Jun 6, 2016, 4:05:49 AM6/6/16
to Ansible Project
This is not working?  Is there a better way to do this?  Or please suggest a fix.

Kai Stian Olstad

unread,
Jun 6, 2016, 10:02:43 AM6/6/16
to ansible...@googlegroups.com
On 06. juni 2016 06:08, John.1209 wrote:
> This is what I have:
>
> ---
> - name: Set DNS variable
> shell: dig {{ ansible_fqdn }} +short
> register: DNSOUT
>
> tasks:
> - name: Verify DNS
> # - command: /usr/bin/echo {{ ansible_fqdn }} not in DNS!
> command: /usr/bin/echo not in DNS!
> when: $ansible_fqdn != DNSOUT
>
> This is not working? Is there a better way to do this? Or please suggest
> a fix.

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

- name: Set DNS variable
command: dig {{ ansible_fqdn }} +short
register: DNSOUT

- name: Verify DNS
command: echo not in DNS!
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!"
when: DNSOUT.stdout == ""

--
Kai Stian Olstad
Reply all
Reply to author
Forward
0 new messages