Final solution:

{% for interface in ansible_interfaces if interface != 'lo' %}{{ 
hostvars[inventory_hostname]['ansible_' + interface]['ipv4']['address'] }} 
{{ lookup('dig', hostvars[inventory_hostname]['ansible_' + 
interface]['ipv4']['address'] + '/PTR').rstrip('.') }} {{ lookup('dig', 
hostvars[inventory_hostname]['ansible_' + interface]['ipv4']['address'] + 
'/PTR').split('.')[0] }}
{% endfor %} 


results in :
1.2.3.4 hostname.mydomain.com hostname
2.3.4.5 hostname-alt.otherdomain.com hostname-alt


This of course assumes that DNS has been properly set beforehand...

On Friday, January 29, 2016 at 11:17:47 AM UTC-6, Dayton Jones wrote:
>
> I'm trying to dynamically set /etc/hosts based on the ipv4 address 
> assigned to all the interfaces on a host... my template reads as such
>
>
> 127.0.0.1       localhost.localdomain localhost
>
> {% for item in ansible_interfaces if item != 'lo' %}
>
> {{ 'ansible_' + item + '.ipv4.address' }} {{ lookup('dig', 'ansible_' + 
> item + '.ipv4.address' + '/PTR') }}
>
> {% endfor %}
>
>
> which results in :
>
> 127.0.0.1 localhost.localdomain localhost
>
> ansible_eth1.ipv4.address NXDOMAIN 
>
> ansible_eth0.ipv4.address NXDOMAIN 
>
>
>
> I've tried several iterations, but I'm struggling to find the proper 
> syntax to get the file to write as expected... is this possible?  Any 
> suggestions greatly appreciated.
>

-- 
You received this message because you are subscribed to the Google Groups 
"Ansible Project" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To post to this group, send email to [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/ansible-project/1a821cc1-3eec-47c7-a3c9-19ed1e8257bd%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to