---
- name: Unbound installed
  community.general.pkgng:
    name: "unbound void-zones-tools"
    state: latest

- name: Unbound enabled
  shell: sysrc unbound_enable="YES"

- name: Unbound config file installed
  copy:
    src: unbound.conf
    dest: /usr/local/etc/unbound/unbound.conf
    owner: root
    mode: 0644
  ignore_errors: true
  notify: Unbound restarted

- name: Unbound service zones file installed
  copy:
    src: service.zones
    dest: /var/unbound/service.zones
    mode: 0644
  notify: Unbound restarted
  tags: zone-update

- name: Unbound unblink zones file installed
  copy:
    src: unblink.zones
    dest: /var/unbound/unblink.zones
    mode: 0644
  notify: Unbound restarted
  tags: zone-update

- name: Void zones installed
  shell: void-zones-update.sh
  ignore_errors: true
  notify: Unbound restarted

- name: Root hints installed
  shell: fetch ftp://ftp.internic.net/domain/named.cache -o /usr/local/etc/unbound/root.hints
  ignore_errors: true
  notify: Unbound restarted

- name: Void zone cronjob configured
  cron:
    name: "Update void-zones-tools"
    special_time: monthly
    job: "/usr/local/bin/void-zones-update.sh && /usr/sbin/service unbound restart"
  ignore_errors: true

- name: Root hints update cronjob configured
  cron:
    name: "Update root hints"
    special_time: monthly
    job: "fetch ftp://ftp.internic.net/domain/named.cache -o /usr/local/etc/unbound/root.hints"
  ignore_errors: true
