{% if taskserv.entries[DOMAIN_POS].domain == "$defaults" -%}
    {% set dns_domain=defaults.main_domain %}
{%- elif taskserv.entries[DOMAIN_POS].domain == "$server" %}
    {%- if server.main_domain == "$defaults"or server.main_domain == ""-%}
        {% set dns_domain=defaults.main_domain %}
    {%- else -%}
        {% set dns_domain=server.main_domain %}
    {%- endif %}
{%- else -%}
    {% set dns_domain=taskserv.entries[DOMAIN_POS].domain %}
{%- endif %}
$ORIGIN {{dns_domain}}.
@       3600 IN SOA sns.dns.icann.org. noc.dns.icann.org. (
            2017042745 ; serial
            7200       ; refresh (2 hours)
            3600       ; retry (1 hour)
            1209600    ; expire (2 weeks)
            3600       ; minimum (1 hour)
            )
        3600 IN NS a.iana-servers.net.
        3600 IN NS b.iana-servers.net.
;
{% if taskserv.entries[DOMAIN_POS] %}
{%- for record in taskserv.entries[DOMAIN_POS].records %}
    {%- if defs.servers[record.server_pos] and defs.servers[record.server_pos].hostname -%}
        {% set hostname = defs.servers[record.server_pos].hostname %}
    {%- else -%}
        {% set hostname = "" %}
    {%- endif -%}
    {%- if record.source == "$hostname" -%}
        {% set source = hostname %}
    {%- else -%}
        {% set source = record.source %}
    {%- endif -%}
    {%- if record.target_ip == "$network_private_ip" and defs.servers[record.server_pos] and defs.servers[record.server_pos].network_private_ip -%}
        {% set target = defs.servers[record.server_pos].network_private_ip %}
    {%- elif record.target_ip == "$network_public_ip" and defs.servers[record.server_pos].ip_addresses.pub -%}
        {% set target = defs.servers[record.server_pos].ip_addresses.pub %}
    {%- else -%}
        {% set target = record.target_ip %}
    {%- endif -%}
 {% if hostname != "" -%}
; {{hostname}}
{%- endif %}
{% if record.rectype == "A" and source and target -%}
{{ source }}.{{dns_domain}}. {{record.ttl}} IN A {{target}} 
{% elif record.rectype == "CNAME" and source and record.value -%}
{{ source }}.{{dns_domain}}. {{record.ttl}} IN CNAME {{record.value}}
{% endif -%}
{%- if hostname != "" and taskserv.entries[DOMAIN_POS].etcd_cluster_name and taskserv.entries[DOMAIN_POS].etcd_cluster_name != "" -%}
{%- for taskserv in defs.servers[record.server_pos].taskservs -%}
{%- if taskserv.name != "etcd" -%}{% continue %}{%- endif -%}
{{ taskserv.entries[DOMAIN_POS].etcd_cluster_name }}.{{dns_domain}}. {{record.ttl}} IN A {{target}} ; {{ hostname }}
{% break %}
{%- endfor -%}
_etcd-server-ssl._tcp.{{dns_domain}}. {{record.etcd_dns_ttl}} IN SRV 0 0 {{record.etcd_peer_port}} {{hostname}}.{{dns_domain}}.
_etcd-server._tcp.{{dns_domain}}. {{record.etcd_dns_ttl}} IN SRV 0 0 {{record.etcd_peer_port}} {{hostname}}.{{dns_domain}}.
_etcd-client-ssl._tcp.{{dns_domain}}. {{record.etcd_dns_ttl}} IN SRV 0 0 {{record.etcd_cli_port}} {{hostname}}.{{dns_domain}}.
_etcd-client._tcp.{{dns_domain}}. {{record.etcd_dns_ttl}} IN SRV  0 0 {{record.etcd_cli_port}} {{hostname}}.{{dns_domain}}.
{% endif %}
{%- endfor -%}
{% endif %}
