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
>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