Add automatic zone load from salt mine.
diff --git a/bind/files/db.zone b/bind/files/db.zone
index 9c263f1..b1af9ed 100644
--- a/bind/files/db.zone
+++ b/bind/files/db.zone
@@ -1,10 +1,10 @@
{%- from "bind/map.jinja" import server with context -%}
-{%- for name, zone in server.zone.iteritems() if name == zone_name %}
-$ORIGIN {{ name }}
+{%- set zone = server.zone.get(zone_name, {}) -%}
+$ORIGIN {{ zone_name }}.
$TTL {{ zone.get('ttl', '86400') }}
-{{ name }} IN SOA {{ name }}. {{ zone.get('root', 'hostmaster.'+name)|replace('@', '.') }}. (
- {{ zone.get('serial', 1) }}
+@ IN SOA {{ zone.get('ns', zone_name) }} {{ zone.get('root', 'hostmaster.'+zone_name)|replace('@', '.') }}. (
+ {{ salt['grains.get']('dnsserial', 1) }}
{{ zone.get('refresh', 604800) }}
{{ zone.get('retry', 86400) }}
{{ zone.get('expire', 2419200) }}
@@ -12,13 +12,20 @@
)
{%- for record in zone.get('records', []) %}
-{{ record.get('name', '@') }} {{ record.get('ttl', '') }}
-{%- for type in record.get('type', []) %}
-{{ type }} {% if type in ['TXT', 'SPF'] %}"{{ record.get('value', []) }}"{% else %}{{ record.get('value', []) }}{% endif %}
+{%- set type = record.get('type', 'A') %}
+{{ record.get('name', '@') }} {{ record.get('ttl', '') }} IN {{ type }} {% if type in ['TXT', 'SPF'] %}"{{ record.get('value', []) }}"{% else %}{{ record.get('value', []) }}{% endif %}
+{%- endfor %}
+{#- Automatic records from salt mine #}
+{%- if zone.get('auto_records', False) %}
+{%- for grains in salt['mine.get']('*', 'grains.items').values() %}
+{%- for record in grains.get('dns_records', []) %}
+{%- for name in record.get('names', []) if '.' in name and name.split('.',1)[1] == zone_name %}
+{{ name.split('.',1)[0] }} IN A {{ record.get('address', '127.0.0.1') }}
{%- endfor %}
{%- endfor %}
{%- endfor %}
+{%- endif %}
{#-
- vim: syntax=jinja
-#}
\ No newline at end of file
+ vim: ft=jinja
+#}
diff --git a/bind/files/named.conf.Debian b/bind/files/named.conf.Debian
index 5134e55..76bec99 100644
--- a/bind/files/named.conf.Debian
+++ b/bind/files/named.conf.Debian
@@ -8,4 +8,4 @@
include "/etc/bind/named.conf.options";
include "/etc/bind/named.conf.local";
-include "/etc/bind/named.conf.default-zones";
\ No newline at end of file
+include "/etc/bind/named.conf.default-zones";
diff --git a/bind/files/reload.conf b/bind/files/reload.conf
new file mode 100644
index 0000000..993203b
--- /dev/null
+++ b/bind/files/reload.conf
@@ -0,0 +1,3 @@
+[Service]
+ExecReload=
+ExecReload=/usr/sbin/rndc -c /etc/rndc.conf reload
diff --git a/bind/files/rndc.conf b/bind/files/rndc.conf
index f61d832..685505b 100644
--- a/bind/files/rndc.conf
+++ b/bind/files/rndc.conf
@@ -1,5 +1,5 @@
{%- from "bind/map.jinja" import client with context -%}
-{%- if client.get('rndc_key') %}
+{%- if client.get('rndc_key') -%}
include "{{ client.rndc_key }}";
{%- endif %}
@@ -20,5 +20,5 @@
{%- include "bind/files/_servers.conf" %}
{#-
- vim: syntax=jinja
+ vim: ft=jinja
#}
diff --git a/bind/map.jinja b/bind/map.jinja
index b072011..69892e7 100644
--- a/bind/map.jinja
+++ b/bind/map.jinja
@@ -1,4 +1,3 @@
-
{%- set server = salt['grains.filter_by']({
'Debian': {
'pkgs': ['bind9', 'bind9utils'],
diff --git a/bind/server/init.sls b/bind/server/init.sls
index 5dd28e2..843e6e6 100644
--- a/bind/server/init.sls
+++ b/bind/server/init.sls
@@ -2,4 +2,4 @@
- bind.server.service
{%- if pillar.bind.server.zone is defined %}
- bind.server.zone
-{%- endif %}
\ No newline at end of file
+{%- endif %}
diff --git a/bind/server/service.sls b/bind/server/service.sls
index 69d5f32..b928ee9 100644
--- a/bind/server/service.sls
+++ b/bind/server/service.sls
@@ -66,4 +66,17 @@
- require:
- pkg: bind_packages
+bind_service_reload:
+ file.managed:
+ - name: /etc/systemd/system/bind9.service.d/reload.conf
+ - source: 'salt://bind/files/reload.conf'
+ - user: root
+ - group: root
+ - mode: 644
+ - makedirs: True
+ module.run:
+ - name: service.systemctl_reload
+ - onchanges:
+ - file: bind_service_reload
+
{%- endif %}
diff --git a/bind/server/zone.sls b/bind/server/zone.sls
index e1a63b6..ce25132 100644
--- a/bind/server/zone.sls
+++ b/bind/server/zone.sls
@@ -11,6 +11,11 @@
- require:
- file: named_directory
+dnsserial_increment:
+ grains.present:
+ - name: dnsserial
+ - value: {{ salt['grains.get']('dnsserial', 1) + 1 }}
+
{%- for name, zone in server.zone.iteritems() %}
{%- if zone.get('type', 'master') == 'master' %}
{# Slave zone files will be created by bind #}