ansible-role-bind9/tasks/main.yml

133 lines
3.5 KiB
YAML
Raw Normal View History

2022-02-21 20:41:31 +00:00
---
- name: Include OS-specific variables
ansible.builtin.include_vars: "{{ ansible_os_family }}.yml"
2022-02-21 20:41:31 +00:00
2022-04-04 14:00:11 +00:00
- name: Install bind and dependencies
2023-02-08 16:56:13 +00:00
ansible.builtin.package:
2022-02-21 20:41:31 +00:00
name: "{{ item }}"
state: present
with_items: "{{ bind_package_names }}"
2022-04-04 14:00:11 +00:00
- name: Create logging directory
2023-02-08 16:56:13 +00:00
ansible.builtin.file:
2022-02-21 20:41:31 +00:00
path: "{{ bind_log_directory }}"
owner: "{{ bind_unix_user }}"
group: "{{ bind_unix_group }}"
2023-02-26 21:22:07 +00:00
mode: "0755"
2022-02-21 20:41:31 +00:00
state: directory
2023-02-08 16:56:13 +00:00
recurse: true
2022-02-21 20:41:31 +00:00
2022-04-04 14:00:11 +00:00
- name: Create config directory
2023-02-08 16:56:13 +00:00
ansible.builtin.file:
2022-04-04 14:00:11 +00:00
path: "{{ bind_config_directory }}"
owner: "{{ bind_unix_user }}"
group: "{{ bind_unix_group }}"
2023-02-26 21:22:07 +00:00
mode: "0755"
2022-04-04 14:00:11 +00:00
state: directory
2023-02-08 16:56:13 +00:00
recurse: true
2022-04-04 14:00:11 +00:00
- name: Remove existing journal files
2022-02-21 20:41:31 +00:00
block:
- name: Find existing journal files
ansible.builtin.find:
2022-02-21 20:41:31 +00:00
path: "{{ bind_config_directory }}"
2023-02-08 16:56:13 +00:00
recurse: true
2022-02-21 20:41:31 +00:00
patterns: "*.jnl"
register: files_to_delete
- name: Delete existing journal files
2023-02-08 16:56:13 +00:00
ansible.builtin.file:
2022-02-21 20:41:31 +00:00
path: "{{ item.path }}"
state: absent
with_items: "{{ files_to_delete.files }}"
2024-05-22 18:22:17 +00:00
- name: Remove existing signed zone files
block:
- name: Find existing signed zone files
ansible.builtin.find:
path: "{{ bind_config_directory }}"
recurse: true
patterns: "*.signed"
register: files_to_delete
- name: Delete existing signed zone files
ansible.builtin.file:
path: "{{ item.path }}"
state: absent
with_items: "{{ files_to_delete.files }}"
- name: Remove existing DNSSEC key directory
block:
- name: Check if DNSSEC key directory exists
ansible.builtin.stat:
path: "{{ bind9_options.key_directory }}"
register: _stat_bind9_options_key_directory
- name: Remove DNSSEC key directory
ansible.builtin.file:
path: "{{ bind9_options.key_directory }}"
state: "absent"
when: _stat_bind9_options_key_directory.stat.exists
- name: Create DNSSEC key directory
ansible.builtin.file:
path: "{{ bind9_options.key_directory }}"
owner: "{{ bind_unix_user }}"
group: "{{ bind_unix_group }}"
mode: "0700"
state: directory
- name: Create DNSSEC files
ansible.builtin.include_tasks: create_dnssec_files.yml
with_items: "{{ bind9_dnssec_keys }}"
no_log: true
loop_control:
loop_var: bind9_dnssec_key
2022-04-04 14:00:11 +00:00
- name: Create DNS-Zone files
ansible.builtin.include_tasks: template_zone_files.yml
2022-02-21 20:41:31 +00:00
with_items:
- "{{ bind9_views }}"
loop_control:
loop_var: view
2022-04-04 14:00:11 +00:00
- name: Create main configuration file
2023-02-08 16:56:13 +00:00
ansible.builtin.template:
2022-04-04 14:00:11 +00:00
src: "etc/named.conf.j2"
dest: "{{ bind_main_config }}"
owner: "{{ bind_unix_user }}"
group: "{{ bind_unix_group }}"
2023-02-26 21:22:07 +00:00
mode: "0644"
2023-02-11 15:00:33 +00:00
notify: Restart named
2022-04-04 14:00:11 +00:00
- name: Create excluded configuration files
2023-02-08 16:56:13 +00:00
ansible.builtin.template:
2022-02-21 20:41:31 +00:00
src: "{{ item }}.j2"
2022-04-04 14:00:11 +00:00
dest: "{{ item | replace('etc/named', bind_config_directory) }}"
2022-02-21 20:41:31 +00:00
owner: "{{ bind_unix_user }}"
group: "{{ bind_unix_group }}"
2023-02-26 21:22:07 +00:00
mode: "0644"
2022-02-21 20:41:31 +00:00
with_items:
2022-04-04 14:00:11 +00:00
- etc/named.conf
- etc/named/named.conf.acl
- etc/named/named.conf.logging
- etc/named/named.conf.options
- etc/named/named.conf.tsigkeys
- etc/named/named.conf.views
2023-02-11 15:00:33 +00:00
notify: Restart named
2022-02-21 20:41:31 +00:00
2022-04-04 14:00:11 +00:00
- name: Start and enabled named
2023-02-08 16:56:13 +00:00
ansible.builtin.systemd:
2022-02-21 20:41:31 +00:00
name: named
state: started
2023-02-08 16:56:13 +00:00
enabled: true
2023-06-09 07:46:02 +00:00
- name: Create rndc.key
ansible.builtin.template:
src: etc/rndc.key.j2
dest: /etc/rndc.key
owner: "{{ bind_unix_user }}"
group: "{{ bind_unix_group }}"
mode: "0600"
when: bind9_rndc_key.name | length > 0 and
bind9_rndc_key.algorithm | length > 0 and
bind9_rndc_key.secret | length > 0