#####################################
### someone's ansible provisioner ###
#####################################
# Part of: https://git.somenet.org/root/pub/somesible.git
# 2017-2026 by someone <someone@somenet.org>
#
---
- name: install dns-server
  apt:
    pkg:
    - bind9
    state: present
    policy_rc_d: 101
  tags: "online"
  ignore_errors: "{{ignore_online_errors | bool}}"


- name: copy bind named.conf.local config file
  copy:
    src: "{{item}}"
    dest: "/etc/bind/named.conf.local"
    mode: 0644
    owner: "root"
    group: "root"
  with_first_found:
    - "{{lookup('env','PWD')}}/host_files/{{inventory_hostname}}/{{role_name}}/named.conf.local"
    - "{{lookup('env','PWD')}}/group_files/{{group_files_group}}/{{role_name}}/named.conf.local"
    - "{{lookup('env','PWD')}}/group_files/all/{{role_name}}/named.conf.local"
    - "default/named.conf.local"
  notify: restart named.service


- name: copy bind named.conf.options config file
  copy:
    src: "{{item}}"
    dest: "/etc/bind/named.conf.options"
    mode: 0644
    owner: "root"
    group: "root"
  with_first_found:
    - "{{lookup('env','PWD')}}/host_files/{{inventory_hostname}}/{{role_name}}/named.conf.options"
    - "{{lookup('env','PWD')}}/group_files/{{group_files_group}}/{{role_name}}/named.conf.options"
    - "{{lookup('env','PWD')}}/group_files/all/{{role_name}}/named.conf.options"
    - "default/named.conf.options"
  notify: restart named.service


- name: create bind db dir
  file:
    path: "/etc/bind/db"
    state: directory
    mode: 0755
    owner: "root"
    group: "root"


# for each zone do a with first found.
- include_tasks: configure-zones.yml
  with_items: "{{named_zones}}"
  loop_control:
    loop_var: zone
  when: named_zones is defined


- name: enable and start named.service
  include_role: name="base/systemd/enable-and-start"
  vars:
    service_name: named.service
