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

- name: setup
  nxos_config: &reset
    lines:
      - no ip name-server 1.1.1.1
      - no ip name-server 2.2.2.2
      - no ip name-server 3.3.3.3
    match: none

- name: configure name_servers
  nxos_system:
    name_servers:
      - 1.1.1.1
      - 2.2.2.2
      - 3.3.3.3
  register: result

- assert:
    that:
      - result.changed == true
      - "'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
  nxos_system:
    name_servers:
      - 1.1.1.1
      - 2.2.2.2
      - 3.3.3.3
  register: result

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

#- name: change to vrf
#  nxos_system:
#    name_servers:
#      - 1.1.1.1
#      - { server: 2.2.2.2, vrf: ansible }
#      - 3.3.3.3
#  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
#  nxos_system:
#    name_servers:
#      - 1.1.1.1
#      - { server: 2.2.2.2, vrf: ansible }
#      - 3.3.3.3
#  register: result
#
#- assert:
#    that:
#      - result.changed == false

- name: remove one
  nxos_system:
    name_servers:
      - 1.1.1.1
      - 2.2.2.2
  register: result

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

- name: default name server
  nxos_system: &defns
    name_servers: default
  register: result

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

- name: Idempotent check
  nxos_system: *defns
  register: result

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

- name: teardown
  nxos_config: *reset
  ignore_errors: yes

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