---
- name: disable stub listener by ensuring the disable line exists on ubuntu 18.04
  lineinfile:
    path: /etc/systemd/resolved.conf
    line: "DNSStubListener=no"
  register: stub_listener_disable_add

- name: ensure stub listener not enabled by removing conflicting allow line if it exists on ubuntu 18.04
  lineinfile:
    path: /etc/systemd/resolved.conf
    state: absent
    line: "DNSStubListener=yes"
  register: stub_listener_enable_remove

- name: replace symbolic link for resolv conf to not point to the stub resolv conf
  file:
    src: /run/systemd/resolve/resolv.conf
    dest: /etc/resolv.conf
    owner: root
    group: root
    state: link
  register: symbolic_link_resolv_conf
  when: (stub_listener_disable_add.changed) or
        (stub_listener_enable_remove.changed)

- name: restart systemd-resolvd
  systemd:
    state: restarted
    daemon_reload: yes
    name: systemd-resolved
  when: (stub_listener_disable_add.changed) or
        (stub_listener_enable_remove.changed)
