---
- fail:
    msg: 'Missing required private DNS server(s)'
  when:
    - external_nsupdate_keys['private'] is undefined
    - hostvars[groups['dns'][0]] is undefined

- fail:
    msg: 'Missing required public DNS server(s)'
  when:
    - external_nsupdate_keys['public'] is undefined
    - hostvars[groups['dns'][0]] is undefined

- name: "Set the private DNS server to use the external value (if provided)"
  set_fact:
    private_dns_server: "{{ external_nsupdate_keys['private']['server'] }}"
  when:
    - external_nsupdate_keys['private'] is defined

- name: "Set the private DNS server to use the provisioned value"
  set_fact:
    private_dns_server: "{{ hostvars[groups['dns'][0]].private_v4 }}"
  when:
    - private_dns_server is undefined

- name: "Set the public DNS server to use the external value (if provided)"
  set_fact:
    public_dns_server: "{{ external_nsupdate_keys['public']['server'] }}"
  when:
    - external_nsupdate_keys['public'] is defined

- name: "Set the public DNS server to use the provisioned value"
  set_fact:
    public_dns_server: "{{ hostvars[groups['dns'][0]].public_v4 }}"
  when:
    - public_dns_server is undefined
