---
- debug: msg="START TRANSPORT:{{ connection.transport }} nxos_vpc sanity test"

- block:
  - name: enable feature vpc
    nxos_feature:
      feature: vpc
      state: enabled
      provider: "{{ connection }}"

  - name: Ensure ntc VRF exists on switch
    nxos_vrf:
      vrf: ntc
      provider: "{{ connection }}"

  - name: Configure vpc
    nxos_vpc: &conf_vpc
      state: present
      domain: 100
      role_priority: 500
      system_priority: 2000
      pkl_dest: 192.168.100.4
      pkl_src: 10.1.100.20
      pkl_vrf: ntc
      peer_gw: true
      delay_restore: 5
      auto_recovery: true
      provider: "{{ connection }}"
    register: result

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

  - name: "Conf Idempotence"
    nxos_vpc: *conf_vpc
    register: result

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

  - name: remove vpc
    nxos_vpc: &rem_vpc
      state: absent
      domain: 100
      role_priority: 32667
      system_priority: 2000
      pkl_dest: 192.168.100.4
      pkl_src: 10.1.100.20
      pkl_vrf: ntc
      peer_gw: true
      delay_restore: 5
      auto_recovery: false
      provider: "{{ connection }}"
    register: result

  - assert: *true

  - name: "Remove Idempotence"
    nxos_vpc: *rem_vpc
    register: result

  - assert: *false

  always:
  - name: remove vrf
    nxos_vrf:
      vrf: ntc
      state: absent
      provider: "{{ connection }}"
    ignore_errors: yes

  - name: disable feature vpc
    nxos_feature:
      feature: vpc
      state: disabled
      provider: "{{ connection }}"
    ignore_errors: yes

- debug: msg="END TRANSPORT:{{ connection.transport }} nxos_vpc sanity test"
