#jinja2: trim_blocks: True, lstrip_blocks: True {% for item in dnsmasq_managed_group | sort %} {% for entry in hostvars[item].dnsmasq | default([]) %} {% set ip = entry.ip | default(hostvars[entry.ip_from].container_ip if entry.ip_from is defined else none) %} {% if ip %} host-record={{ entry.name }},{{ ip }} {% endif %} {% endfor %} {% endfor %}