Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add zone management #2

Open
wants to merge 10 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 11 additions & 1 deletion README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,17 @@ Server dns zones
example2.com:
semantic-checks: False
template: default

soa:
email: [email protected]
serial: 20190409001
master: ns.example2.com
records:
- name: mail
type: A
content: 192.168.1.1
- name: '@'
type: MX
content: '10 mail'

Read more
=========
Expand Down
63 changes: 44 additions & 19 deletions knot/files/knot.conf
Original file line number Diff line number Diff line change
@@ -1,65 +1,90 @@
{%- from "knot/map.jinja" import server with context %}

{% macro val(name,value) -%}
{{ name }}: {% if value is string and value[0] != '[' %}"{{ value }}"{% else %}{{ value }}{% endif %}
{%- endmacro %}

server:
listen: {{ server.bind.ipv4.address }}@{{ server.bind.ipv4.port }}
listen: {{ server.bind.ipv6.address }}@{{ server.bind.ipv6.port }}
user: "knot:knot"
{%- if server.options is defined %}
{%- for param_name, param_value in server.options.items() %}
{{ val(param_name, param_value) }}
{%- endfor %}
{%- endif %}

{%- if server.log is defined %}
log:
- target: syslog
any: info
{%- for target_name, target in server.log.items() %}
- target: {{ target }}
{%- for param_name, param_value in target.items() %}
{{ val(param_name, param_value) }}
{%- endfor %}
{%- endfor %}
{%- endif %}

{%- if server.key is defined %}
key:
{%- for key_name, key in server.key.iteritems() %}
{%- for key_name, key in server.key.items() %}
- id: {{ key_name }}
{%- for param_name, param_value in key.iteritems() %}
{{ param_name }}: {% if param_value is string %}"{{ param_value }}"{% else %}{{ param_value }}{% endif %}
{%- for param_name, param_value in key.items() %}
{{ val(param_name, param_value) }}
{%- endfor %}
{%- endfor %}
{%- endif %}


{%- if server.remote is defined %}
remote:
{%- for remote_name, remote in server.remote.iteritems() %}
{%- for remote_name, remote in server.remote.items() %}
- id: {{ remote_name }}
{%- for param_name, param_value in remote.iteritems() %}
{{ param_name }}: {{ param_value }}
{%- for param_name, param_value in remote.items() %}
{{ val(param_name, param_value) }}
{%- endfor %}
{%- endfor %}
{%- endif %}


{%- if server.acl is defined %}
acl:
{%- for acl_name, acl in server.acl.iteritems() %}
{%- for acl_name, acl in server.acl.items() %}
- id: {{ acl_name }}
{%- for param_name, param_value in acl.iteritems() %}
{{ param_name }}: {{ param_value }}
{%- for param_name, param_value in acl.items() %}
{{ val(param_name, param_value) }}
{%- endfor %}
{%- endfor %}
{%- endif %}


{%- if server.policy is defined %}
policy:
{%- for policy_name, policy in server.policy.items() %}
- id: {{ policy_name }}
{%- for param_name, param_value in policy.items() %}
{{ val(param_name, param_value) }}
{%- endfor %}
{%- endfor %}
{%- endif %}


{%- if server.template is defined %}
template:
{%- for template_name, template in server.template.iteritems() %}
{%- for template_name, template in server.template.items() %}
- id: {{ template_name }}
{%- for param_name, param_value in template.iteritems() %}
{{ param_name }}: {% if param_value is string %}"{{ param_value }}"{% else %}{{ param_value }}{% endif %}
{%- for param_name, param_value in template.items() %}
{{ val(param_name, param_value) }}
{%- endfor %}
{%- endfor %}
{%- endif %}


{%- if server.zone is defined %}
zone:
{%- for zone_name, zone in server.zone.iteritems() %}
{%- for zone_name, zone in server.zone.items() %}
- domain: {{ zone_name }}
{%- for param_name, param_value in zone.iteritems() %}
{%- if param_name != "records" %}
{{ param_name }}: {% if param_value is string %}"{{ param_value }}"{% else %}{{ param_value }}{% endif %}
{%- for param_name, param_value in zone.items() %}
{%- if param_name != "records" and param_name != "soa" %}
{{ val(param_name, param_value) }}
{%- endif %}
{%- endfor %}
{%- endfor %}
Expand Down
16 changes: 16 additions & 0 deletions knot/files/zone
Original file line number Diff line number Diff line change
@@ -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|default(1) }} ; 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 %}
8 changes: 6 additions & 2 deletions knot/map.jinja
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,12 @@
{%- load_yaml as base_defaults %}
Debian:
pkgs:
- knot
- dnsutils
- knot

'*':
pkgs:
- knot
bind:
ipv4:
address: 0.0.0.0
Expand All @@ -16,4 +20,4 @@ Debian:
config: /etc/knot/knot.conf
{%- endload %}

{%- set server = salt['grains.filter_by'](base_defaults, merge=salt['pillar.get']('knot:server')) %}
{%- set server = salt['grains.filter_by'](base_defaults, merge=salt['pillar.get']('knot:server')) %}
29 changes: 29 additions & 0 deletions knot/server.sls
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,35 @@ 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 }}

{{ zone_name }}_zone_reload:
cmd.run:
- name: knotc zone-check {{ zone_name }} && knotc zone-reload {{ zone_name }}
- watch:
- file: {{ zone_name }}_zone

{%- endif %}
{%- endfor %}
{%- endif %}

knot_service:
service.running:
- name: {{ server.service }}
Expand Down