---
- name: Install Unbound package
  apt:
    name: unbound
    state: present
  when: ansible_distribution == "Debian"
  tags:
  - unbound

- name: Retrieve list of root DNS servers
  get_url:
    url: https://www.internic.net/domain/named.cache
    dest: /etc/unbound/root.hints
    force: yes
    mode: "0644"
  notify: reload unbound
  tags:
  - unbound

- name: Copy Unbound config
  template:
    src: unbound.conf.j2
    dest: /etc/unbound/unbound.conf
    owner: root
    group: root
    mode: "0644"
  when: ansible_distribution == "Debian"
  notify: reload unbound
  tags:
  - unbound

- name: Starting and enabling Unbound
  service:
    name: unbound
    enabled: yes
    state: started
  tags:
  - unbound
