nsd: adapt for new version of NSD and allow to configure most parameters related to version (nsd3/nsd4)

This commit is contained in:
Baptiste Jonglez 2017-09-01 10:55:03 +02:00
parent 2ae5fd8b38
commit cdf6821679
5 changed files with 36 additions and 23 deletions

12
defaults/main.yml Normal file
View File

@ -0,0 +1,12 @@
---
# Default variables, suitable for nsd4 on Debian (jessie or above)
nsd_version: "nsd"
nsd_service_name: "nsd"
nsd_pkg_name: "nsd"
nsd_control_program: "/usr/sbin/nsd-control"
nsd_config_dir: "/etc/nsd"
nsd_zones_config_file: "/etc/nsd/zones.conf"
nsd_primary_zones_dir: "/etc/nsd/primary"
nsd_secondary_zones_dir: "/etc/nsd/secondary"

View File

@ -4,14 +4,15 @@
# nsd MUST rebuild its database before being restarted. Otherwise, it will
# fail to start.
- name: rebuild nsd3 database
command: /usr/sbin/nsdc rebuild
- name: rebuild nsd database
command: "{{ nsd_control_program }} rebuild"
when: nsd_version == 'nsd3'
- name: reload nsd3 database
command: /usr/sbin/nsdc reload
- name: reload nsd database
command: "{{ nsd_control_program }} reload"
- name: restart nsd3
service: name=nsd3 state=restarted
- name: restart nsd
service: name={{ nsd_service_name }} state=restarted
- name: notify slaves
command: /usr/sbin/nsdc notify
command: "{{ nsd_control_program }} notify"

View File

@ -1,32 +1,32 @@
---
- name: Install nsd3
apt: pkg=nsd3 state=present
- name: Install nsd
apt: pkg={{ nsd_pkg_name }} state=present
- name: Create primary zone directory
file: path="{{ primary_zones_dir }}" state=directory owner=root group=root mode=0755
file: path="{{ nsd_primary_zones_dir }}" state=directory owner=root group=root mode=0755
- name: Create secondary zone directory
file: path="{{ secondary_zones_dir }}" state=directory owner=nsd group=nsd mode=0755
file: path="{{ nsd_secondary_zones_dir }}" state=directory owner=nsd group=nsd mode=0755
- name: Configure nsd3 zones
template: src=zones_config.j2 dest="{{ zones_config_file }}" owner=root group=root mode=0644 validate='nsd-checkconf %s'
- name: Configure nsd zones
template: src=zones_config.j2 dest="{{ nsd_zones_config_file }}" owner=root group=root mode=0644 validate='nsd-checkconf %s'
notify:
- rebuild nsd3 database
- reload nsd3 database
- rebuild nsd database
- reload nsd database
- name: Create base nsd3 configuration file
- name: Create base nsd configuration file
template: src=config.j2 dest="{{ nsd_config_dir }}/nsd.conf" owner=root group=root mode=0644 validate='nsd-checkconf %s'
notify:
- restart nsd3
- restart nsd
- name: Copy content of primary zones
copy: src="files/nsd/{{ item.zone_filename }}" dest="{{ primary_zones_dir }}/{{ item.zone_filename }}" owner=root group=root mode=0644
copy: src="files/nsd/{{ item.zone_filename }}" dest="{{ nsd_primary_zones_dir }}/{{ item.zone_filename }}" owner=root group=root mode=0644
with_items: "{{ nsd_primary_zones }}"
notify:
- rebuild nsd3 database
- reload nsd3 database
- rebuild nsd database
- reload nsd database
- notify slaves

View File

@ -29,5 +29,5 @@ server:
# Include zone definitions
include: "{{ zones_config_file }}"
include: "{{ nsd_zones_config_file }}"

View File

@ -20,7 +20,7 @@ key:
# Primary zone definition for {{ zone.zone_name }}
zone:
name: "{{ zone.zone_name }}"
zonefile: "{{ primary_zones_dir }}/{{ zone.zone_filename }}"
zonefile: "{{ nsd_primary_zones_dir }}/{{ zone.zone_filename }}"
{% for slave in zone.slaves|default([]) %}
notify: {{ slave.ip }} "{{ slave.tsig_key|default('NOKEY') }}"
provide-xfr: {{ slave.ip }} "{{ slave.tsig_key|default('NOKEY') }}"
@ -35,7 +35,7 @@ zone:
# Secondary zone definition for {{ zone.zone_name }}
zone:
name: "{{ zone.zone_name }}"
zonefile: "{{ secondary_zones_dir }}/{{ zone.zone_name }}"
zonefile: "{{ nsd_secondary_zones_dir }}/{{ zone.zone_name }}"
{% for master in zone.masters|default([]) %}
allow-notify: {{ master.ip }} "{{ master.tsig_key|default('NOKEY') }}"
request-xfr: AXFR {{ master.ip }} "{{ master.tsig_key|default('NOKEY') }}"