---
- name: Install packages for bind9
  ansible.builtin.package:
    name:
      - bind9
      - bind9-host
      - cron
    state: present

- name: Create zone directory
  ansible.builtin.file:
    path: /etc/bind/zones
    owner: bind
    group: bind
    mode: 0700
    state: directory

- name: Create log directory
  ansible.builtin.file:
    path: /var/log/named
    owner: bind
    group: bind
    mode: 0700
    state: directory

- name: Copy bind configuration files
  ansible.builtin.template:
    src: "{{ item }}.j2"
    dest: "/etc/bind/{{ item }}"
    owner: root
    group: root
    mode: 0644
  loop:
    - named.conf
    - named.conf.options
    - named.conf.local
  notify: Restart bind

- name: Create keys directory
  ansible.builtin.file:
    path: /etc/bind/keys
    owner: root
    group: bind
    mode: 0750
    state: directory

- name: Add cron dnssec
  ansible.builtin.template:
    src: dnssec.j2
    dest: /etc/cron.weekly/dnssec
    owner: root
    group: root
    mode: 0700
  tags: bind