# {{ ansible_managed }} {% for ip in dnsmasq_host_ips %} {% endfor %} {% set last_host = groups['all'] | last %} {% for host in groups['all'] %} {% set hostnames = [hostvars[host]['inventory_hostname']] + [hostvars[host]['inventory_hostname_short']] + dnsmasq_host_aliases %} {% for ip in dnsmasq_host_ips %} {{ ip }} {{ hostnames | select() | join(' ') }} {% endfor %} {% if host != last_host %} {% endif %} {% endfor %}