You seem to expect that the resulting string of {{ 'ansible_' + item +
'.ipv4.address' }} will then be 'retemplated', that won't happen
Also, don't use 'item' as that is reserved for ansible loops, the
following is the say to 'dynamically' access host facts:
{% for interface in ansible_interfaces if item != 'lo' %}
{{ hostvars[inventory_hostname]['ansible_' + interface+ '.ipv4.address'] }} ...
On Fri, Jan 29, 2016 at 10:33 AM, Dayton Jones <[email protected]> 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/abeeffdc-5c60-4ab0-986b-15e72e23922f%40googlegroups.com.
> For more options, visit https://groups.google.com/d/optout.
--
Brian Coca
--
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/CAJ5XC8nH8FLJZ_K%2BczeMfPzbB85hjO_pY33atO%2BHhjLKhruEKA%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.