{% set service_dict = item.value %}
<?xml version="1.0" standalone='no'?><!--*-nxml-*-->
<!DOCTYPE service-group SYSTEM "avahi-service.dtd">

<!-- {{ ansible_managed }} -->
{% if service_dict.comment|d() %}

{{ service_dict.comment | comment(style='xml') }}
{% endif %}

<service-group>

  <name replace-wildcards="{{ 'yes' if service_dict.replace_wildcards|d(True)|bool else 'no' }}">{{ service_dict.name if service_dict.name|d() else '%h' }}</name>

{% for service in service_dict.services %}
{%   if service.protocol|d() %}
  <service protocol="{{ service.protocol }}">
{%   else %}
  <service>
{%   endif %}
    <type>{{ service.type }}</type>
{%   if service.subtype|d() %}
{%     if service.subtype is string %}
    <subtype>{{ service.subtype }}</subtype>
{%     else %}
{%       for element in service.subtype %}
    <subtype>{{ element }}</subtype>
{%       endfor %}
{%     endif %}
{%   endif %}
    <port>{{ service.port }}</port>
{%   if service.domain|d() %}
    <domain-name>{{ service.domain }}</domain-name>
{%   elif service.domain_name|d() %}
    <domain-name>{{ service.domain_name }}</domain-name>
{%   endif %}
{%   if service.hostname|d() %}
    <host-name>{{ service.hostname }}</host-name>
{%   elif service.host_name|d() %}
    <host-name>{{ service.host_name }}</host-name>
{%   elif service.fqdn|d() %}
    <host-name>{{ service.fqdn }}</host-name>
{%   endif %}
{%   if service.txt|d() %}
{%     if service.txt is string %}
    <txt-record>{{ service.txt }}</txt-record>
{%     else %}
{%       for element in service.txt %}
    <txt-record>{{ element }}</txt-record>
{%       endfor %}
{%     endif %}
{%   endif %}
{%   if service.txt_record|d() %}
{%     if service.txt_record is string %}
    <txt-record>{{ service.txt_record }}</txt-record>
{%     else %}
{%       for element in service.txt_record %}
    <txt-record>{{ element }}</txt-record>
{%       endfor %}
{%     endif %}
{%   endif %}
  </service>

{% endfor %}
</service-group>
