---
- block:
  - name: Install the unbound resolver packages
    apt: pkg={{ unbound_pkgs }} state=latest cache_valid_time=1800 update_cache=yes

  - name: Install the unbound config files
    template: src={{ item }} dest=/etc/unbound/unbound.conf.d/{{ item }}
    with_items:
      - unbound-server.conf
      - unbound-remote-control.conf
    notify: Restart unbound
  
  - name: On bionic, stop systemd-resolvd because it interferes
    service: name=systemd-resolved state=stopped enabled=no
    when:
      - ansible_distribution == "Ubuntu"
      - ansible_service_mgr == 'systemd'
      - ansible_distribution_major_version >= '18'

  - name: Ensure that the unbound service is started and enabled
    service: name=unbound state=restarted enabled=yes    

  tags: [ 'unbound' ]