---
- debug: msg="START connection={{ ansible_connection }} nxos_vxlan_vtep sanity test"
- debug: msg="Using provider={{ connection.transport }}"
  when: ansible_connection == "local"

- block:
  - name: "Apply N7K specific setup config"
    include: targets/nxos_vxlan_vtep/tasks/platform/n7k/setup.yaml
    when: platform is match('N7K')

  - name: "Enable feature nv overlay"
    nxos_config: 
      commands:
        - feature nv overlay
      match: none
      provider: "{{ connection }}"

  - block:
    - name: configure vxlan_vtep
      nxos_vxlan_vtep: &configure9
        interface: nve1
        description: "abcd"
        host_reachability: true
        source_interface: Loopback0
        source_interface_hold_down_time: 30
        shutdown: false
        provider: "{{ connection }}"
      register: result
  
    - assert: &true
        that:
          - "result.changed == true"
  
    - name: "Conf Idempotence"
      nxos_vxlan_vtep: *configure9
      register: result

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

    - name: reset vxlan_vtep
      nxos_vxlan_vtep: &def9
        interface: nve1
        description: default
        host_reachability: false
        source_interface_hold_down_time: default
        source_interface: default
        shutdown: true
        provider: "{{ connection }}"
      register: result
  
    - assert: *true
  
    - name: "reset Idempotence"
      nxos_vxlan_vtep: *def9
      register: result

    - assert: *false

    when: (platform is search('N9K'))

  - block:
    - name: configure vxlan_vtep
      nxos_vxlan_vtep: &configure7
        interface: nve1
        description: default
        host_reachability: true
        source_interface: Loopback0
        shutdown: false
        provider: "{{ connection }}"
      register: result
  
    - assert:
        that:
          - "result.changed == true"
  
    - name: "Conf Idempotence"
      nxos_vxlan_vtep: *configure7
      register: result

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

    - name: reset vxlan_vtep
      nxos_vxlan_vtep: &def7
        interface: nve1
        description: default
        host_reachability: false
        source_interface: default
        shutdown: true
        provider: "{{ connection }}"
      register: result
  
    - assert: *true
  
    - name: "reset Idempotence"
      nxos_vxlan_vtep: *def7
      register: result

    - assert: *false

    when: (platform is search('N7K'))

  - name: remove vxlan_vtep
    nxos_vxlan_vtep: &remove
      interface: nve1
      description: default
      host_reachability: true
      source_interface: Loopback0
      source_interface_hold_down_time: 30
      shutdown: true
      provider: "{{ connection }}"
      state: absent
    register: result

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

  - name: "Remove Idempotence"
    nxos_vxlan_vtep: *remove
    register: result

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

  when: (platform is search("N7K|N9K"))

  always:
  - name: "Apply N7K specific cleanup config"
    include: targets/nxos_vxlan_vtep/tasks/platform/n7k/cleanup.yaml
    when: platform is match('N7K')

  - name: "Disable feature nv overlay"
    nxos_feature: 
      feature: nve
      provider: "{{ connection }}"
      state: disabled
    ignore_errors: yes

- debug: msg="END connection={{ ansible_connection }} nxos_vxlan_vtep sanity test"