initial commit
diff --git a/README.md b/README.md
new file mode 100644
index 0000000..cd8c6a8
--- /dev/null
+++ b/README.md
@@ -0,0 +1,16 @@
+
+# Bind DNS service
+
+bind:
+  configured_zones:
+    sub.domain.com:
+      type: master
+      notify: False
+    1.168.192.in-addr.arpa:
+      type: master
+      notify: False
+
+available_zones:
+  sub.domain.org:
+    file: db.sub.domain.org
+    masters: "192.168.0.1;"
\ No newline at end of file
diff --git a/files/logrotate b/files/logrotate
new file mode 100644
index 0000000..174b74b
--- /dev/null
+++ b/files/logrotate
@@ -0,0 +1,11 @@
+/var/log/bind9/query.log {
+    rotate 7
+    daily
+    missingok
+    notifempty
+    sharedscripts
+    copytruncate
+    compress
+    create 0664 bind root
+    su
+}
\ No newline at end of file
diff --git a/files/named.conf b/files/named.conf
new file mode 100644
index 0000000..5134e55
--- /dev/null
+++ b/files/named.conf
@@ -0,0 +1,11 @@
+// This is the primary configuration file for the BIND DNS server named.
+//
+// Please read /usr/share/doc/bind9/README.Debian.gz for information on the
+// structure of BIND configuration files in Debian, *BEFORE* you customize
+// this configuration file.
+//
+// If you are just adding zones, please do that in /etc/bind/named.conf.local
+
+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
diff --git a/files/named.conf.default-zones b/files/named.conf.default-zones
new file mode 100644
index 0000000..6b13d53
--- /dev/null
+++ b/files/named.conf.default-zones
@@ -0,0 +1,28 @@
+// prime the server with knowledge of the root servers
+zone "." {
+      type hint;
+      file "/etc/bind/db.root";
+};
+
+// be authoritative for the localhost forward and reverse zones, and for
+// broadcast zones as per RFC 1912
+
+zone "localhost" {
+      type master;
+      file "/etc/bind/db.local";
+};
+
+zone "127.in-addr.arpa" {
+      type master;
+      file "/etc/bind/db.127";
+};
+
+zone "0.in-addr.arpa" {
+      type master;
+      file "/etc/bind/db.0";
+};
+
+zone "255.in-addr.arpa" {
+      type master;
+      file "/etc/bind/db.255";
+};
\ No newline at end of file
diff --git a/files/named.conf.local b/files/named.conf.local
new file mode 100644
index 0000000..d7f9b6b
--- /dev/null
+++ b/files/named.conf.local
@@ -0,0 +1,31 @@
+//
+// Do any local configuration here
+//
+
+// Consider adding the 1918 zones here, if they are not used in your
+// organization
+//include "/etc/bind/zones.rfc1918";
+
+{% for key,args in salt['pillar.get']('bind:configured_zones', {}).iteritems() -%}
+{%- set file = salt['pillar.get']("available_zones:" + key + ":file") %}
+{%- set masters = salt['pillar.get']("available_zones:" + key + ":masters") %}
+zone "{{ key }}" {
+  type {{ args['type'] }};
+  file "zones/{{ file }}";
+  {% if args['type'] == "master" -%}
+    {% if args['notify'] -%}
+  notify yes;
+    {% else -%}
+  notify no;
+    {%- endif -%}
+  {% else -%}
+  notify no;
+  masters { {{ masters }} };
+  {%- endif %}
+};
+{% endfor %}
+
+logging {
+  channel "querylog" { file "/var/log/bind9/query.log"; print-time yes; };
+  category queries { querylog; };
+};
\ No newline at end of file
diff --git a/files/named.conf.options b/files/named.conf.options
new file mode 100644
index 0000000..80ee0a3
--- /dev/null
+++ b/files/named.conf.options
@@ -0,0 +1,21 @@
+options {
+        directory "/var/cache/bind";
+
+        // If there is a firewall between you and nameservers you want
+        // to talk to, you may need to fix the firewall to allow multiple
+        // ports to talk. See http://www.kb.cert.org/vuls/id/800113
+
+        // If your ISP provided one or more IP addresses for stable
+        // nameservers, you probably want to use them as forwarders.
+        // Uncomment the following block, and insert the addresses replacing
+        // the all-0's placeholder.
+
+        // forwarders {
+        // 0.0.0.0;
+        // };
+
+        auth-nxdomain no; # conform to RFC1035
+        {% if salt['pillar.get']('bind:config:ipv6', 'False') %}
+        listen-on-v6 { {{ salt['pillar.get']('bind:config:ipv6_listen', 'any') }}; };
+        {% endif %}
+};
\ No newline at end of file
diff --git a/init.sls b/init.sls
new file mode 100644
index 0000000..8c8a197
--- /dev/null
+++ b/init.sls
@@ -0,0 +1,5 @@
+
+include:
+{% if pillar.bind.server is defined %}
+- bind.server
+{% endif %}
diff --git a/map.jinja b/map.jinja
new file mode 100644
index 0000000..7411982
--- /dev/null
+++ b/map.jinja
@@ -0,0 +1,22 @@
+{% set server = salt['grains.filter_by']({
+    'Debian': {
+        'pkgs': ['bind9', 'bind9utils'],
+        'service': 'bind9',
+        'config': '/etc/bind/named.conf',
+        'local_config': '/etc/bind/named.conf.local',
+        'options_config': '/etc/bind/named.conf.options',
+        'default_zones_config': '/etc/bind/named.conf.default-zones',
+        'named_directory': '/var/cache/bind/zones',
+        'user': 'root',
+        'group': 'bind'
+    },
+    'RedHat': {
+        'pkgs': ['bind'],
+        'service': 'named',
+        'config': '/etc/named.conf',
+        'local_config': '/etc/named.conf.local',
+        'named_directory': '/var/named/data',
+        'user': 'root',
+        'group': 'named'
+    },
+}, merge=salt['pillar.get']('bind:server')) %}
diff --git a/server/init.sls b/server/init.sls
new file mode 100644
index 0000000..55e6006
--- /dev/null
+++ b/server/init.sls
@@ -0,0 +1,3 @@
+include:
+- bind.server.service
+- bind.server.zone
\ No newline at end of file
diff --git a/server/service.sls b/server/service.sls
new file mode 100644
index 0000000..cd7d3d7
--- /dev/null
+++ b/server/service.sls
@@ -0,0 +1,126 @@
+{% from "bind/map.jinja" import server with context %}
+
+bind_packages:
+  pkg.installed:
+    - pkgs: {{ server.pkgs|json }}
+
+named_directory:
+  file.directory:
+    - name: {{ map.named_directory }}
+    - user: {{ salt['pillar.get']('bind:config:user', map.user) }}
+    - group: {{ salt['pillar.get']('bind:config:group', map.group) }}
+    - mode: 775
+    - makedirs: True
+    - require:
+      - pkg: bind
+
+{% if grains.os_family == 'RedHat' %}
+bind_config:
+  file.managed:
+    - name: {{ map.config }}
+    - source: 'salt://bind/files/redhat/named.conf'
+    - template: jinja
+    - user: {{ salt['pillar.get']('bind:config:user', map.user) }}
+    - group: {{ salt['pillar.get']('bind:config:group', map.group) }}
+    - mode: {{ salt['pillar.get']('bind:config:mode', '640') }}
+    - require:
+      - pkg: bind
+    - watch_in:
+      - service: bind
+
+bind_local_config:
+  file.managed:
+    - name: {{ map.local_config }}
+    - source: 'salt://bind/files/redhat/named.conf.local'
+    - template: jinja
+    - user: {{ salt['pillar.get']('bind:config:user', map.user) }}
+    - group: {{ salt['pillar.get']('bind:config:group', map.group) }}
+    - mode: {{ salt['pillar.get']('bind:config:mode', '644') }}
+    - require:
+      - pkg: bind
+    - watch_in:
+      - service: named
+{% endif %}
+
+{% if grains['os_family'] == 'Debian' %}
+bind_config:
+  file:
+    - managed
+    - name: {{ map.config }}
+    - source: 'salt://bind/files/debian/named.conf'
+    - template: jinja
+    - user: {{ salt['pillar.get']('bind:config:user', map.user) }}
+    - group: {{ salt['pillar.get']('bind:config:group', map.group) }}
+    - mode: {{ salt['pillar.get']('bind:config:mode', '644') }}
+    - require:
+      - pkg: bind
+    - watch_in:
+      - service: bind
+
+bind_local_config:
+  file:
+    - managed
+    - name: {{ map.local_config }}
+    - source: 'salt://bind/files/debian/named.conf.local'
+    - template: jinja
+    - user: {{ salt['pillar.get']('bind:config:user', map.user) }}
+    - group: {{ salt['pillar.get']('bind:config:group', map.group) }}
+    - mode: {{ salt['pillar.get']('bind:config:mode', '644') }}
+    - require:
+      - pkg: bind
+    - watch_in:
+      - service: bind
+
+bind_options_config:
+  file:
+    - managed
+    - name: {{ map.options_config }}
+    - source: 'salt://bind/files/debian/named.conf.options'
+    - template: jinja
+    - user: {{ salt['pillar.get']('bind:config:user', map.user) }}
+    - group: {{ salt['pillar.get']('bind:config:group', map.group) }}
+    - mode: {{ salt['pillar.get']('bind:config:mode', '644') }}
+    - require:
+      - pkg: bind
+    - watch_in:
+      - service: bind
+
+bind_default_zones:
+  file:
+    - managed
+    - name: {{ map.default_zones_config }}
+    - source: 'salt://bind/files/debian/named.conf.default-zones'
+    - template: jinja
+    - user: {{ salt['pillar.get']('bind:config:user', map.user) }}
+    - group: {{ salt['pillar.get']('bind:config:group', map.group) }}
+    - mode: {{ salt['pillar.get']('bind:config:mode', '644') }}
+    - require:
+      - pkg: bind
+    - watch_in:
+      - service: bind
+
+/var/log/bind9:
+  file:
+    - directory
+    - user: root
+    - group: bind
+    - mode: 775
+    - template: jinja
+
+
+/etc/logrotate.d/bind9:
+  file:
+    - managed
+    - source: salt://bind/files/debian/logrotate_bind
+    - user: root
+    - group: root
+
+{%- endif %}
+
+bind_service:
+  service.running:
+    - name: {{ server.service }}
+    - enable: true
+    - reload: true
+    - require:
+      - pkg: bind_packages
diff --git a/server/zone.sls b/server/zone.sls
new file mode 100644
index 0000000..e69de29
--- /dev/null
+++ b/server/zone.sls