Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Get IP from inventory which defined FQDN only

In the inventory file, I define FQDN values only. To render template file (Jinja), do we have any solution, in Ansible, to get the IP addresses from these hosts?

Inventory file:

[example_instance]
example1.com
example2.com

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>Solution :

You can use the dig lookup for that. But, mind that you also need the dnspython library installed on your controller for it to work.

So, given the two tasks:

- pip:
    name: dnspython
  delegate_to: localhost
  run_once: yes

- debug:
    msg: "{{ lookup('dig', inventory_hostname) }}"

This would give you two IPs in return, in your case:

ok: [example1.com] => 
  msg: 192.185.44.208
ok: [example2.com] => 
  msg: 34.102.136.180
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading