---
- 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: Copy Unbound configuration file
  template: src=unbound.conf.j2 dest=/etc/unbound/unbound.conf
  notify:
    - restart unbound

- name: Create Unbound systemd unit file directory
  file: path=/etc/systemd/system/unbound.service.d state=directory
  tags:
    - firejail

- name: Push Unbound socket unit file
  copy: src=unbound-service-override.conf dest=/etc/systemd/system/unbound.service.d/override.conf
  notify:
    - reload systemd config
    - restart unbound
  tags:
    - firejail

- name: Remove Unbound systemd unit PID file line
  lineinfile: dest=/usr/lib/systemd/system/unbound.service
              state=absent
              line="PIDFile=/run/unbound.pid"
  notify:
    - reload systemd config
    - restart unbound
  tags:
    - firejail

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

- name: Configure resolvconf to use Unbound
  lineinfile: dest=/etc/resolvconf.conf
              state=present
              line="name_servers=127.0.0.1"
