Fixes and support for zones
diff --git a/.gitignore b/.gitignore
new file mode 100644
index 0000000..bacd7c7
--- /dev/null
+++ b/.gitignore
@@ -0,0 +1,4 @@
+tests/build/
+*.swp
+*.pyc
+.ropeproject
diff --git a/README.md b/README.md
index ca5d65b..c36f678 100644
--- a/README.md
+++ b/README.md
@@ -8,6 +8,8 @@
enabled: true
zone:
sub.domain.com:
+ ttl: 86400
+ root: "hostmaster@domain.com"
type: master
records:
- name: @
@@ -21,8 +23,9 @@
type: slave
notify: true
masters:
- - dns01.domain.com
- - dns02.domain.com
+ # Masters must be specified by IP address
+ - 8.8.8.8
+ - 8.8.4.4
dnssec:
enabled: true
# Don't hide version
diff --git a/bind/files/db.zone b/bind/files/db.zone
new file mode 100644
index 0000000..d96e9f9
--- /dev/null
+++ b/bind/files/db.zone
@@ -0,0 +1,23 @@
+{%- from "bind/map.jinja" import server with context -%}
+{%- for name, zone in server.zone.iteritems() if name == zone_name %}
+$ORIGIN {{ name }}
+$TTL {{ zone.get('ttl', '86400') }}
+
+{{ name }} IN SOA {{ name }}. {{ zone.get('root', 'hostmaster.'+name)|replace('@', '.') }}. (
+ 1 ; serial
+ {{ zone.get('refresh', 604800) }}
+ {{ zone.get('retry', 86400) }}
+ {{ zone.get('expire', 2419200) }}
+ {{ zone.get('minimum', 86400) }}
+ )
+
+{%- for record in zone.get('records', []) %}
+{{ record.get('name', '@') }} {{ record.get('ttl', '') }} {{ type }} {% if type in ['TXT', 'SPF'] %}"{{ value }}"{% else %}{{ value }}{% endif %}
+{%- endfor %}
+{%- endfor %}
+
+{%- endfor %}
+
+{#-
+ vim: syntax=jinja
+#}
diff --git a/bind/files/named.conf.local b/bind/files/named.conf.local
index 98013bc..ee76b71 100644
--- a/bind/files/named.conf.local
+++ b/bind/files/named.conf.local
@@ -1,10 +1,10 @@
{%- from "bind/map.jinja" import server with context -%}
-{%- for name, zone in server.get('zone', {}) %}
+{%- for name, zone in server.get('zone', {}).iteritems() %}
zone "{{ name }}" {
type {{ zone.get('type', 'master') }};
- file {{ server.zones_dir }}/{{ name }}.conf;
+ file {{ server.zones_dir }}/db.{{ name }};
{%- if zone.get('type', 'master') != 'master' %}
notify {% 'yes' if zone.get('notify', False) else 'no' %};
diff --git a/bind/server/zone.sls b/bind/server/zone.sls
index 43885e9..e1a63b6 100644
--- a/bind/server/zone.sls
+++ b/bind/server/zone.sls
@@ -1,4 +1,36 @@
{%- from "bind/map.jinja" import server with context %}
{%- if server.enabled %}
-{%- endif %}
\ No newline at end of file
+zones_directory:
+ file.directory:
+ - name: {{ server.zones_dir }}
+ - user: root
+ - group: {{ server.group }}
+ - mode: 775
+ - makedirs: True
+ - require:
+ - file: named_directory
+
+{%- for name, zone in server.zone.iteritems() %}
+{%- if zone.get('type', 'master') == 'master' %}
+{# Slave zone files will be created by bind #}
+
+bind_zone_{{ name }}:
+ file.managed:
+ - name: {{ server.zones_dir }}/db.{{ name }}
+ - source: 'salt://bind/files/db.zone'
+ - template: jinja
+ - user: root
+ - group: {{ server.group }}
+ - mode: 640
+ - require:
+ - file: zones_directory
+ - watch_in:
+ - service: bind_service
+ - defaults:
+ zone_name: {{ name }}
+
+{%- endif %}
+{%- endfor %}
+
+{%- endif %}
diff --git a/tests/pillar/server.sls b/tests/pillar/server.sls
index 8c2853a..21728ca 100644
--- a/tests/pillar/server.sls
+++ b/tests/pillar/server.sls
@@ -22,8 +22,9 @@
type: slave
notify: true
masters:
- - dns01.domain.com
- - dns02.domain.com
+ # Masters must be specified by IP address
+ - 8.8.8.8
+ - 8.8.4.4
dnssec:
enabled: true
validation: true