dig lookup multiple hosts

15 views
Skip to first unread message

rjwagn...@gmail.com

unread,
Dec 5, 2018, 1:55:46 PM12/5/18
to Ansible Project
Hey all - I'm trying to lookup the IPs for a list of FQDNs.  The dig lookup is close to what I need, but it appears to return a list of IPs for a single FQDN; when using with_items, it yields each of the IPs for that FQDN (https://docs.ansible.com/ansible/2.5/plugins/lookup/dig.html).  Any idea how I can use with_items to iterate over the list of FQDNs and store the resulting list of IPs?

Something sort of like:
---
- hosts: all
  vars:
    db_hosts=['host1.example.com', 'host2.example.com']
  tasks:
    - debug: msg='IP is {{ item }}'
      with_items: "{{ lookup('dig', 'BLAH', wantlist=False) }}"

but what to put in for BLAH if I want to get the IPs for the list given by db_hosts?

Rob

Kai Stian Olstad

unread,
Dec 5, 2018, 3:08:31 PM12/5/18
to ansible...@googlegroups.com
I'm might misunderstand you question, but if you turn it around I think get your answer

- debug: msg='IP for {{ item }} is {{ lookup('dig', item) }}'
with_items: "{{ db_hosts }}"

--
Kai Stian Olstad


Rob Wagner

unread,
Dec 5, 2018, 6:16:18 PM12/5/18
to ansible...@googlegroups.com
Thanks Kai. That worked. I think I don’t quite understand lookup plugins (aside from with_items). I’ll keep researching.

Rob
> --
> You received this message because you are subscribed to a topic in the Google Groups "Ansible Project" group.
> To unsubscribe from this topic, visit https://groups.google.com/d/topic/ansible-project/4EeglD0c4yg/unsubscribe.
> To unsubscribe from this group and all its topics, 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/1897030.6mZVLSW9GO%40x1.
> For more options, visit https://groups.google.com/d/optout.
Reply all
Reply to author
Forward
0 new messages