add nsd role

This commit is contained in:
Ryan Cavicchioni 2020-01-01 11:17:43 -06:00
parent 2da2a1affc
commit 2b4fdbc661
Signed by: ryanc
GPG Key ID: 877EEDAF9245103D
4 changed files with 97 additions and 0 deletions

View File

@ -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 }}"

View File

@ -0,0 +1,10 @@
---
- name: reload nsd
service:
name: "{{ nsd_service_name }}"
state: reloaded
- name: restart nsd
service:
name: "{{ nsd_service_name }}"
state: restarted

36
roles/nsd/tasks/main.yaml Normal file
View File

@ -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 }}"

View File

@ -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 %}