From 2b4fdbc661503d35c18dcfa5a7c2f485f3b42b28 Mon Sep 17 00:00:00 2001 From: Ryan Cavicchioni Date: Wed, 1 Jan 2020 11:17:43 -0600 Subject: [PATCH] add nsd role --- roles/nsd/defaults/main.yaml | 17 ++++++++++++++++ roles/nsd/handlers/main.yaml | 10 +++++++++ roles/nsd/tasks/main.yaml | 36 +++++++++++++++++++++++++++++++++ roles/nsd/templates/nsd.conf.j2 | 34 +++++++++++++++++++++++++++++++ 4 files changed, 97 insertions(+) create mode 100644 roles/nsd/defaults/main.yaml create mode 100644 roles/nsd/handlers/main.yaml create mode 100644 roles/nsd/tasks/main.yaml create mode 100644 roles/nsd/templates/nsd.conf.j2 diff --git a/roles/nsd/defaults/main.yaml b/roles/nsd/defaults/main.yaml new file mode 100644 index 0000000..bdbeaf8 --- /dev/null +++ b/roles/nsd/defaults/main.yaml @@ -0,0 +1,17 @@ +--- +nsd_package_name: nsd +nsd_package_state: present + +nsd_service_name: nsd +nsd_service_state: started +nsd_service_enabled: yes + +nsd_etc_path: /etc/nsd +nsd_zone_path: "{{ nsd_etc_path }}/zones" + +nsd_server_config: + verbosity: 2 + zonesdir: "{{ nsd_zone_path }}" + ip-address: + - "{{ ansible_default_ipv4.address }}" + - "{{ ansible_default_ipv6.address }}" diff --git a/roles/nsd/handlers/main.yaml b/roles/nsd/handlers/main.yaml new file mode 100644 index 0000000..87d1387 --- /dev/null +++ b/roles/nsd/handlers/main.yaml @@ -0,0 +1,10 @@ +--- +- name: reload nsd + service: + name: "{{ nsd_service_name }}" + state: reloaded + +- name: restart nsd + service: + name: "{{ nsd_service_name }}" + state: restarted diff --git a/roles/nsd/tasks/main.yaml b/roles/nsd/tasks/main.yaml new file mode 100644 index 0000000..13dd91e --- /dev/null +++ b/roles/nsd/tasks/main.yaml @@ -0,0 +1,36 @@ +--- +- name: install package + package: + name: "{{ nsd_package_name }}" + state: "{{ nsd_package_state }}" + +- name: create zone directory + file: + path: "{{ nsd_zone_path }}" + state: directory + +- name: configure + template: + src: nsd.conf.j2 + dest: "{{ nsd_etc_path }}/nsd.conf" + owner: root + group: root + mode: 0644 + notify: restart nsd + +- name: configure zones + copy: + src: "files/nsd/zones/{{ item.filename | default(item.name + '.zone') }}" + dest: "{{ nsd_zone_path }}/{{ item.name }}.zone" + owner: root + group: nsd + mode: 0640 + validate: "nsd-checkzone {{ item.name }} %s" + loop: "{{ nsd_zones | default([]) }}" + notify: reload nsd + +- name: manage service + service: + name: "{{ nsd_service_name }}" + state: "{{ nsd_service_state }}" + enabled: "{{ nsd_service_enabled }}" diff --git a/roles/nsd/templates/nsd.conf.j2 b/roles/nsd/templates/nsd.conf.j2 new file mode 100644 index 0000000..e6f1993 --- /dev/null +++ b/roles/nsd/templates/nsd.conf.j2 @@ -0,0 +1,34 @@ +# {{ ansible_managed }} + +{% if nsd_server_config is defined and + nsd_server_config is mapping %} +server: +{% for k, v in nsd_server_config.items() %} +{% if v is string or v is number %} + {{ k }}: {{ v }} +{% elif v is sequence %} +{% for vv in v %} + {{ k }}: {{ vv }} +{% endfor %} +{% endif %} +{% endfor %} +{% endif %} + +{% if nsd_zones is defined and + nsd_zones is sequence %} +{% for zone in nsd_zones %} +{% if zone is defined and + zone is mapping %} +zone: +{% for k, v in zone.items() %} +{% if v is string %} + {{ k }}: {{ v }} +{% elif v is sequence %} +{% for vv in v %} + {{ k }}: {{ vv }} +{% endfor %} +{% endif %} +{% endfor %} +{% endif %} +{% endfor %} +{% endif %}