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

- block:
  - name: remove configuration
    cnos_system: &remove
      state: absent
    register: result
    ignore_errors: yes

  - name: configure lookup_enabled
    cnos_system: &dlo
      lookup_enabled: true
      state: present
    register: result

  - name: configure hostname and domain-name
    cnos_system: &hostname
      hostname: switch
      domain_name: test.example.com
    register: result

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

  - name: Idempotence check
    cnos_system: *hostname
    register: result

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

  - name: configure name servers
    cnos_system: &ns
      name_servers:
        - 8.8.8.8
        - 8.8.4.4
    register: result

  - assert: *true

  - name: Idempotence check
    cnos_system: *ns
    register: result

  - assert: *false

  - name: configure name servers with VRF support
    cnos_system: &nsv
      name_servers:
        - { server: 8.8.8.8, vrf: management }
        - { server: 8.8.4.4, vrf: management }
    register: result

  - assert: *true

  - name: Idempotence check
    cnos_system: *nsv
    register: result

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

  - name: configure lookup_enabled1
    cnos_system: &ndlo
      lookup_enabled: false
    register: result

  - assert: *true

  - name: Idempotence check
    cnos_system: *ndlo
    register: result

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

  - name: configure lookup_enabled2
    cnos_system: *dlo
    register: result

  - assert: *true

  - name: Idempotence check
    cnos_system: *dlo
    register: result

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

  - name: default configuration
    cnos_system: &default
      hostname: default
      domain_name: default
      name_servers: default
    register: result

  - assert: *true

  - name: Idempotence check
    cnos_system: *default
    register: result

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

  always:
  - name: remove configuration
    cnos_system: *remove

  - name: Re-configure hostname
    cnos_system: *hostname

- debug: msg="END connection={{ ansible_connection }}/sanity.yaml" 
