---
- debug: msg="START eapi/set_name_servers.yaml"

- name: setup
  eos_config:
    lines:
      - no ip name-server
      - vrf definition ansible
    timeout: 30
    match: none
    provider: "{{ eapi }}"

- name: configure name_servers
  eos_system:
    name_servers:
      - 1.1.1.1
      - 2.2.2.2
      - 3.3.3.3
    timeout: 30
    provider: "{{ eapi }}"
  register: result

- assert:
    that:
      - result.changed == true
      - result.commands|length == 3
      - "'ip name-server 1.1.1.1' in result.commands"
      - "'ip name-server 2.2.2.2' in result.commands"
      - "'ip name-server 3.3.3.3' in result.commands"

- name: verify name_servers
  eos_system:
    name_servers:
      - 1.1.1.1
      - 2.2.2.2
      - 3.3.3.3
    timeout: 30
    provider: "{{ eapi }}"
  register: result

- assert:
    that:
      - result.changed == false

#- name: change to vrf
#  eos_system:
#    name_servers:
#      - 1.1.1.1
#      - { server: 2.2.2.2, vrf: ansible }
#      - 3.3.3.3
#    provider: "{{ eapi }}"
#  register: result

#- assert:
#    that:
#      - result.changed == true
#      - result.commands|length == 2
#      - "'no ip name-server 2.2.2.2' in result.commands"
#      - "'ip name-server 2.2.2.2 vrf ansible' in result.commands"

#- name: verify change to vrf
#  eos_system:
#    name_servers:
#      - 1.1.1.1
#      - { server: 2.2.2.2, vrf: ansible }
#      - 3.3.3.3
#    provider: "{{ eapi }}"
#  register: result

#- assert:
#    that:
#      - result.changed == false

- name: remove one
  eos_system:
    name_servers:
      - 1.1.1.1
      - 2.2.2.2
    timeout: 30
    provider: "{{ eapi }}"
  register: result

- assert:
    that:
      - result.changed == true
      - result.commands|length == 1
      - "'no ip name-server 3.3.3.3' in result.commands"

- name: teardown
  eos_config:
    lines:
      - no ip domain lookup source-interface
      - no vrf definition ansible
    timeout: 30
    match: none
    provider: "{{ eapi }}"

- debug: msg="END eapi/set_name_servers.yaml"
