Add ddns updates.
diff --git a/bind/files/db.zone b/bind/files/db.zone
index b1af9ed..1183350 100644
--- a/bind/files/db.zone
+++ b/bind/files/db.zone
@@ -1,14 +1,14 @@
{%- from "bind/map.jinja" import server with context -%}
{%- set zone = server.zone.get(zone_name, {}) -%}
$ORIGIN {{ zone_name }}.
-$TTL {{ zone.get('ttl', '86400') }}
+$TTL {{ zone.get('ttl', '300') }}
@ 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) }}
- {{ zone.get('minimum', 86400) }}
+ {{ zone.get('refresh', 43200) }}
+ {{ zone.get('retry', 180) }}
+ {{ zone.get('expire', 1209600) }}
+ {{ zone.get('nxttl', 10) }}
)
{%- for record in zone.get('records', []) %}
diff --git a/bind/files/named.conf.local b/bind/files/named.conf.local
index 3780d27..42cfd64 100644
--- a/bind/files/named.conf.local
+++ b/bind/files/named.conf.local
@@ -26,7 +26,7 @@
};
{%- if zone.get('auto_records', False) %}
allow-update {
- 127.0.0.1;
+ localhost;
};
{%- endif %}
};
diff --git a/bind/map.jinja b/bind/map.jinja
index 69892e7..d73b772 100644
--- a/bind/map.jinja
+++ b/bind/map.jinja
@@ -22,9 +22,12 @@
}, merge=salt['pillar.get']('bind:server')) %}
{%- set client = salt['grains.filter_by']({
+ 'defaults': {
+ 'ddns_ttl': 300
+ },
'Debian': {
'pkgs': ['bind9utils'],
'rndc_config': '/etc/rndc.conf',
'rndc_key': '/etc/bind/rndc.key',
},
-}, merge=salt['pillar.get']('bind:client')) %}
+}, merge=salt['pillar.get']('bind:client'), base='defaults') %}
diff --git a/bind/reactor/node_register.sls b/bind/reactor/node_register.sls
new file mode 100644
index 0000000..6c9b613
--- /dev/null
+++ b/bind/reactor/node_register.sls
@@ -0,0 +1,17 @@
+{%- from "bind/map.jinja" import client with context %}
+{%- for record in data.data.grains.get('dns_records', []) %}
+{%- for name in record.get('names', []) if '.' in name %}
+{%- set hostname, domain = name.split('.',1) %}
+
+bind_node_register_{{ name }}:
+ local.ddns.add_host:
+ - tgt: bind:server:zone:{{ domain }}:type:master
+ - tgt_type: pillar
+ - args:
+ - zone: {{ domain }}
+ - name: {{ hostname }}
+ - ttl: {{ client.get('ddns_ttl', 300) }}
+ - ip: {{ record.get('address', '127.0.0.127') }}
+
+{%- endfor %}
+{%- endfor %}
diff --git a/bind/register.sls b/bind/register.sls
new file mode 100644
index 0000000..ac6292b
--- /dev/null
+++ b/bind/register.sls
@@ -0,0 +1,5 @@
+send_register_event:
+ event.send:
+ - name: dns/node/register
+ - with_grains:
+ - dns_records
diff --git a/bind/server/service.sls b/bind/server/service.sls
index b928ee9..67ca7f7 100644
--- a/bind/server/service.sls
+++ b/bind/server/service.sls
@@ -62,7 +62,6 @@
service.running:
- name: {{ server.service }}
- enable: true
- - reload: true
- require:
- pkg: bind_packages
diff --git a/bind/server/zone.sls b/bind/server/zone.sls
index ce25132..c81164b 100644
--- a/bind/server/zone.sls
+++ b/bind/server/zone.sls
@@ -14,11 +14,21 @@
dnsserial_increment:
grains.present:
- name: dnsserial
- - value: {{ salt['grains.get']('dnsserial', 1) + 1 }}
+ - value: {{ salt['grains.get']('dnsserial', 1) + 1000 }}
+
+bind_service_stop:
+ service.dead:
+ - name: {{ server.service }}
{%- for name, zone in server.zone.iteritems() %}
{%- if zone.get('type', 'master') == 'master' %}
-{# Slave zone files will be created by bind #}
+{#- Slave zone files will be created by bind #}
+
+bind_zone_{{ name }}_jnl:
+ file.absent:
+ - name: {{ server.zones_dir }}/db.{{ name }}.jnl
+ - require:
+ - service: bind_service_stop
bind_zone_{{ name }}:
file.managed:
@@ -30,12 +40,14 @@
- mode: 640
- require:
- file: zones_directory
- - watch_in:
- - service: bind_service
- defaults:
zone_name: {{ name }}
{%- endif %}
{%- endfor %}
+bind_service_start:
+ service.running:
+ - name: {{ server.service }}
+
{%- endif %}
diff --git a/metadata/service/register.yml b/metadata/service/register.yml
new file mode 100644
index 0000000..942e606
--- /dev/null
+++ b/metadata/service/register.yml
@@ -0,0 +1,2 @@
+applications:
+- bind.register