From cdf682167907d91faf093b6a33756a77f10011fb Mon Sep 17 00:00:00 2001 From: Baptiste Jonglez Date: Fri, 1 Sep 2017 10:55:03 +0200 Subject: [PATCH] nsd: adapt for new version of NSD and allow to configure most parameters related to version (nsd3/nsd4) --- defaults/main.yml | 12 ++++++++++++ handlers/main.yml | 15 ++++++++------- tasks/main.yml | 26 +++++++++++++------------- templates/config.j2 | 2 +- templates/zones_config.j2 | 4 ++-- 5 files changed, 36 insertions(+), 23 deletions(-) create mode 100644 defaults/main.yml diff --git a/defaults/main.yml b/defaults/main.yml new file mode 100644 index 0000000..868e23d --- /dev/null +++ b/defaults/main.yml @@ -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" diff --git a/handlers/main.yml b/handlers/main.yml index 399f476..ce5866f 100644 --- a/handlers/main.yml +++ b/handlers/main.yml @@ -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" diff --git a/tasks/main.yml b/tasks/main.yml index d758710..3a7fb66 100644 --- a/tasks/main.yml +++ b/tasks/main.yml @@ -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 diff --git a/templates/config.j2 b/templates/config.j2 index 144bee7..b6bcea2 100644 --- a/templates/config.j2 +++ b/templates/config.j2 @@ -29,5 +29,5 @@ server: # Include zone definitions -include: "{{ zones_config_file }}" +include: "{{ nsd_zones_config_file }}" diff --git a/templates/zones_config.j2 b/templates/zones_config.j2 index b492493..a08241b 100644 --- a/templates/zones_config.j2 +++ b/templates/zones_config.j2 @@ -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') }}"