2019-02-18 21:36:09 +00:00
|
|
|
---
|
2023-06-30 09:16:45 +00:00
|
|
|
- name: Set fact bind_zone_play if it empty
|
|
|
|
ansible.builtin.set_fact:
|
|
|
|
bind_zones_play: "{{ bind_zones_play | default([]) + [item] }}"
|
|
|
|
loop: "{{ bind_zones | dict2items }}"
|
2020-03-06 22:31:43 +00:00
|
|
|
loop_control:
|
2023-06-30 09:16:45 +00:00
|
|
|
label: "{{ item.key }}"
|
2019-02-18 21:36:09 +00:00
|
|
|
when: >
|
2023-06-30 09:16:45 +00:00
|
|
|
(item.value.state is not defined or item.value.state != "absent")
|
2019-02-18 21:36:09 +00:00
|
|
|
and (bind_zones_subset is not defined or item.key in bind_zones_subset)
|
2018-05-26 07:51:21 +00:00
|
|
|
|
2023-06-30 09:16:45 +00:00
|
|
|
- name: Create zone folder
|
|
|
|
ansible.builtin.file:
|
|
|
|
path: "/etc/bind/zones/{{ item.key }}"
|
2018-03-31 15:50:50 +00:00
|
|
|
owner: bind
|
|
|
|
group: bind
|
|
|
|
mode: 0755
|
|
|
|
state: directory
|
2020-03-06 22:31:43 +00:00
|
|
|
loop_control:
|
2023-06-30 09:16:45 +00:00
|
|
|
label: "{{ item.key }}"
|
|
|
|
loop: "{{ bind_zones_play }}"
|
2018-03-31 15:50:50 +00:00
|
|
|
|
2023-06-30 09:16:45 +00:00
|
|
|
- name: Copy zone files
|
|
|
|
ansible.builtin.template:
|
2018-03-28 15:45:57 +00:00
|
|
|
src: db.j2
|
2023-06-30 09:16:45 +00:00
|
|
|
dest: "/etc/bind/zones/{{ item.key }}/db"
|
2018-03-28 15:45:57 +00:00
|
|
|
owner: root
|
|
|
|
group: root
|
|
|
|
mode: 0644
|
2023-06-30 09:16:45 +00:00
|
|
|
loop: "{{ bind_zones_play }}"
|
2020-03-06 22:31:43 +00:00
|
|
|
loop_control:
|
2023-06-30 09:16:45 +00:00
|
|
|
label: "{{ item.key }}"
|
2018-03-28 15:45:57 +00:00
|
|
|
register: zone
|
2023-06-30 09:16:45 +00:00
|
|
|
notify: Reload bind
|
2018-03-28 15:45:57 +00:00
|
|
|
|
2023-06-30 09:16:45 +00:00
|
|
|
- name: Dnssec sign # noqa risky-shell-pipe no-changed-when
|
|
|
|
ansible.builtin.shell: >
|
2019-02-18 21:36:09 +00:00
|
|
|
dnssec-signzone -3 $(head -n 1000 /dev/urandom | sha1sum | cut -b 1-16) -A -N INCREMENT
|
|
|
|
-o {{ item.item.key }} -t /etc/bind/zones/{{ item.item.key }}/db
|
2018-03-28 15:45:57 +00:00
|
|
|
args:
|
|
|
|
chdir: /etc/bind/keys
|
2023-06-30 09:16:45 +00:00
|
|
|
loop: "{{ zone.results }}"
|
2020-03-06 22:31:43 +00:00
|
|
|
loop_control:
|
2023-06-30 09:16:45 +00:00
|
|
|
label: "{{ item.item.key }}"
|
2019-02-18 21:36:09 +00:00
|
|
|
when: item.item.key in bind_dnssec and item.changed
|
2023-06-30 09:16:45 +00:00
|
|
|
notify: Reload bind
|
2018-03-31 15:50:50 +00:00
|
|
|
|
2023-06-30 09:16:45 +00:00
|
|
|
- name: Get zones files
|
|
|
|
ansible.builtin.find:
|
2018-03-31 15:50:50 +00:00
|
|
|
path: /etc/bind/zones
|
|
|
|
file_type: directory
|
|
|
|
recurse: no
|
|
|
|
register: zone_folders
|
|
|
|
|
2023-06-30 09:16:45 +00:00
|
|
|
- name: Delete old zone file
|
|
|
|
ansible.builtin.file:
|
|
|
|
path: "{{ item.path }}"
|
2018-03-31 15:50:50 +00:00
|
|
|
state: absent
|
2023-06-30 09:16:45 +00:00
|
|
|
loop: "{{ zone_folders.files }}"
|
2020-03-06 22:31:43 +00:00
|
|
|
loop_control:
|
2023-06-30 09:16:45 +00:00
|
|
|
label: "{{ item.path | basename }}"
|
2019-02-18 21:36:09 +00:00
|
|
|
when: >
|
|
|
|
item.path|basename not in bind_zones or
|
2023-06-30 09:16:45 +00:00
|
|
|
("state" in bind_zones[item.path | basename] and bind_zones[item.path | basename].state == "absent")
|