From 48fa3382a8ae1369342f05cc116c0b98565dfd40 Mon Sep 17 00:00:00 2001 From: Michal Hrusecky Date: Tue, 9 Apr 2019 06:41:01 +0200 Subject: [PATCH] Add possibility to manage zone files --- knot/files/knot.conf | 2 +- knot/files/zone | 16 ++++++++++++++++ knot/server.sls | 22 ++++++++++++++++++++++ 3 files changed, 39 insertions(+), 1 deletion(-) create mode 100644 knot/files/zone diff --git a/knot/files/knot.conf b/knot/files/knot.conf index ba4fe48..b2b5b8f 100644 --- a/knot/files/knot.conf +++ b/knot/files/knot.conf @@ -58,7 +58,7 @@ zone: {%- for zone_name, zone in server.zone.items() %} - domain: {{ zone_name }} {%- for param_name, param_value in zone.items() %} - {%- if param_name != "records" %} + {%- if param_name != "records" and param_name != "soa" %} {{ param_name }}: {% if param_value is string %}"{{ param_value }}"{% else %}{{ param_value }}{% endif %} {%- endif %} {%- endfor %} diff --git a/knot/files/zone b/knot/files/zone new file mode 100644 index 0000000..6431cfe --- /dev/null +++ b/knot/files/zone @@ -0,0 +1,16 @@ +; This file is managed by Salt +; Do not edit manually! + +$ORIGIN {{ zone_name }}. +$TTL {{ ttl|default('3600') }} + +@ SOA {{ soa['master'] }}. {{ soa['email'] }}. ( + {{ soa.serial }} ; serial + {{ soa.refresh|default('6h') }} ; refresh + {{ soa.retry|default('1h') }} ; retry + {{ soa.expire|default('6h') }} ; expire + {{ soa.minimum|default('6h') }}) ; minimum + +{%- for rec in records %} +{{ rec.name }} {{ rec.ttl|default('') }} {{ rec.type }} {{ rec.content }} +{%- endfor %} diff --git a/knot/server.sls b/knot/server.sls index 1bbeae6..4039843 100644 --- a/knot/server.sls +++ b/knot/server.sls @@ -16,6 +16,28 @@ knot_config: - require: - pkg: knot_packages +{%- if server.zone is defined %} +{%- for zone_name, zone in server.zone.items() %} +{%- if zone.records is defined %} + +{{ zone_name }}_zone: + file.managed: + - name: {{ zone.storage|default('/var/lib/knot') }}/{{ zone_file|default(zone_name + ".zone") }} + - template: jinja + - source: salt://knot/files/zone + - user: knot + - group: knot + - mode: 0600 + - require: + - file: knot_config + - context: + zone_name: {{ zone_name }} + soa: {{ zone.soa }} + records: {{ zone.records }} +{%- endif %} +{%- endfor %} +{%- endif %} + knot_service: service.running: - name: {{ server.service }}