---
- name: Install Unbound
  pacman:
    name: unbound
    state: present

- name: Download root hints
  get_url:
    url: https://www.internic.net/domain/named.cache
    dest: /etc/unbound/root.hints
    force: yes

- name: Verify unbound resolvconf config file exists
  copy:
    content: ""
    dest: /etc/unbound/resolvconf.conf
    force: false

- name: Copy Unbound configuration file
  template:
    src: unbound.conf.j2
    dest: /etc/unbound/unbound.conf
  notify:
    - restart unbound

- name: Enable and start Unbound
  service:
    name: unbound.service
    enabled: yes
    state: started

- name: Push Unbound root hits update service file
  copy:
    src: roothints.service
    dest: /etc/systemd/system/roothints.service
  notify:
    - reload systemd config

- name: Push Unbound root hits update timer file
  copy:
    src: roothints.timer
    dest: /etc/systemd/system/roothints.timer
  notify:
    - reload systemd config
    - restart roothints

- include_tasks: roles/nmtrust/tasks/unit.yml
  vars:
      unit: roothints.timer
      run_on: "{{ unbound.roothints_update }}"
