# Load distro-specific variables
- include_vars: "{{ ansible_distribution | lower }}.yml"
  tags: always

- block:
  - name: Nameserver | unbound | install and configure
    when:
      - unbound is defined
      - unbound is true
      - powerdns_recursor is not defined or powerdns_recursor is false
    block:
      - name: Nameserver | unbound | install
        include_tasks: install_unbound.yml
      - name: Nameserver | unbound | configure
        include_tasks: configure_unbound_snmpd.yml

  - name: Nameserver | unbound | disable systemd-resolved
    include_tasks: disable-systemd-resolved.yml
    when: bind is true or unbound is true or powerdns_recursor is true

  - name: Nameserver | powerdns-recursor | install and configure
    when:
      - powerdns_recursor is defined
      - powerdns_recursor is true
      - unbound is not defined or unbound is false
    block:
      - name: Nameserver| powerdns-recursor | install
        include_tasks: install_powerdns_recursor.yml
      - name: Nameserver | powerdns-recursor | configure
        include_tasks: configure_powerdns_recursor_snmpd.yml

  - name: Nameserver | bind | install and configure
    when:
      - bind is defined
      - bind is true
      - powerdns_server is not defined or powerdns_server is false
    block:
      - name: Nameserver | bind | install
        include_tasks: install_bind.yml
      - name: Nameserver | bind | configure
        include_tasks: configure_bind_snmpd.yml

  - name: Nameserver | powerdns-server | install and configure
    when:
      - powerdns_server is defined
      - powerdns_server is true
      - bind is not defined or bind is false
    block:
      - name: Nameserver | powerdns-server | install
        include_tasks: install_powerdns_server.yml
      - name: Nameserver | powerdns-server | configure
        include_tasks: configure_powerdns_server_snmpd.yml

  rescue:
    - set_fact: task_failed=true
