aboutsummaryrefslogtreecommitdiffstats
path: root/roles/dns
diff options
context:
space:
mode:
authorAaron LI <aly@aaronly.me>2018-03-03 00:18:45 +0800
committerAaron LI <aly@aaronly.me>2018-03-14 11:35:07 +0800
commite3e2ee76b6df3f16f8aac92914c07a38170953e8 (patch)
tree5f10efd5b9acbc01f925457b258db92b2af40657 /roles/dns
parentbb51dfab00ba345f03d2f8cf87b320ccf98c1742 (diff)
downloadansible-dfly-vps-e3e2ee76b6df3f16f8aac92914c07a38170953e8.tar.bz2
dns/nsd: use fileglob lookup to help zones templating; also check zone files
Diffstat (limited to 'roles/dns')
-rw-r--r--roles/dns/tasks/main.yml24
1 files changed, 20 insertions, 4 deletions
diff --git a/roles/dns/tasks/main.yml b/roles/dns/tasks/main.yml
index efc9669..68663f7 100644
--- a/roles/dns/tasks/main.yml
+++ b/roles/dns/tasks/main.yml
@@ -58,18 +58,34 @@
command: nsd-control-setup
when: not stat_result.stat.exists
+- name: NSD - get the list of zone files
+ set_fact:
+ zonefiles: "{{ lookup('fileglob', '../templates/zones/*.j2', wantlist=True) }}"
+
+- debug: var=zonefiles
+
- name: NSD - create zones directory
file:
path: /usr/local/etc/nsd/zones
state: directory
- name: NSD - generate zone files
+ vars:
+ domain: "{{ item | basename | regex_replace('\\.zone\\.j2', '') }}"
template:
src: "{{ item }}"
- dest: /usr/local/etc/nsd/zones/{{ item | basename | regex_replace('\.j2', '') }}
- # NOTE: `with_fileglob` always operates from `files/`
- with_fileglob:
- - "../templates/zones/*.j2"
+ dest: "/usr/local/etc/nsd/zones/{{ domain }}.zone"
+ # XXX: `validate` doesn't work with `with_items`???
+ validate: "nsd-checkzone {{ domain }} %s"
+ with_items: "{{ zonefiles }}"
+ notify: reload-nsd
+
+# XXX: the above `validate` doesn't work with `with_items`???
+- name: NSD - check zone files
+ vars:
+ domain: "{{ item | basename | regex_replace('\\.zone\\.j2', '') }}"
+ command: "nsd-checkzone {{ domain }} /usr/local/etc/nsd/zones/{{ domain }}.zone"
+ with_items: "{{ zonefiles }}"
# NOTE: requires variable `zonefiles`
- name: NSD - generate configuration