Ansible-Roles/roles/named/templates/reverse_zone_standalone.j2
2026-05-08 22:12:36 +03:00

68 lines
2.9 KiB
Django/Jinja
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

{#
# Самостоятельная обратная зона.
# PTR-записи задаются явно через ptr_records, не зависит от прямой зоны и networks.
#
# Формат ptr_records:
# - name: '221' # последний октет (или октеты для /16, например '0.201')
# ptr: host.domain. # целевое FQDN (с точкой на конце или без)
#}
{% set _zone_data = {
'ttl': named_zone_ttl,
'domain': item.name,
'mname': item.name_servers | default([]),
'rname': item.hostmaster_email | default('hostmaster.' + item.name),
'refresh': named_zone_time_to_refresh,
'retry': named_zone_time_to_retry,
'expire': named_zone_time_to_expire,
'minimum': named_zone_minimum_ttl,
'records': item.ptr_records | default([])
} %}
{#
# Сравниваем хэш текущих данных зоны с сохранённым, чтобы обновлять serial
# только при реальных изменениях содержимого.
#}
{% set _zone = {'hash': _zone_data | string | hash('md5')} %}
{% for _result in named_reverse_standalone_hashes | default([]) if _result.name == item.name %}
{% set _hash_serial = _result.hash.split(' ')[2:] %}
{% if _hash_serial and _hash_serial[0] == _zone['hash'] %}
{% set _ = _zone.update({'serial': _hash_serial[1]}) %}
{% else %}
{% set _ = _zone.update({'serial': named_timestamp.stdout}) %}
{% endif %}
{% endfor %}
{% if _zone.serial is not defined %}
{% set _ = _zone.update({'serial': named_timestamp.stdout}) %}
{% endif %}
; Hash: {{ _zone['hash'] }} {{ _zone['serial'] }}
; Обратная зона {{ _zone_data['domain'] }}
{{ ansible_managed | comment(decoration='; ') }}
$TTL {{ _zone_data['ttl'] }}
$ORIGIN {{ _zone_data['domain'] }}.
{% if _zone_data['mname'] | length > 0 %}
@ IN SOA {{ _zone_data['mname'] | first }}{% if not _zone_data['mname'] | first | regex_search('\.$') %}.{% endif %} {{ _zone_data['rname'] }}{% if not _zone_data['rname'] | regex_search('\.$') %}.{% endif %} (
{% else %}
@ IN SOA {{ ansible_hostname }}. {{ _zone_data['rname'] }}{% if not _zone_data['rname'] | regex_search('\.$') %}.{% endif %} (
{% endif %}
{{ _zone['serial'] }}
{{ _zone_data['refresh'] }}
{{ _zone_data['retry'] }}
{{ _zone_data['expire'] }}
{{ _zone_data['minimum'] }} )
{% for ns in _zone_data['mname'] %}
IN NS {{ ns }}{% if not ns | regex_search('\.$') %}.{% endif %}
{% endfor %}
{% for record in _zone_data['records'] -%}
{% if record.ptr is defined -%}
{{ record.name.ljust(16) }} IN PTR {{ record.ptr }}{{ '.' if not record.ptr | regex_search('\.$') }}
{% elif record.cname is defined -%}
{{ record.name.ljust(16) }} IN CNAME {{ record.cname }}
{% elif record.dns is defined -%}
{{ record.name.ljust(16) }} IN NS {{ record.dns }}
{% endif -%}
{% endfor %}