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

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

- name: configure lookup_source
  eos_system:
    lookup_source: Management1
    timeout: 30
    provider: "{{ eapi }}"
  register: result

- assert:
    that:
      - result.changed == true
      - "'ip domain lookup source-interface Management1' in result.commands"

- name: verify lookup_source
  eos_system:
    lookup_source: Management1
    timeout: 30
    provider: "{{ eapi }}"
  register: result

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

- name: change to vrf
  eos_system:
    lookup_source:
      - interface: Management1
        vrf: ansible
    timeout: 30
    provider: "{{ eapi }}"
  register: result

- assert:
    that:
      - result.changed == true
      - "'no ip domain lookup source-interface Management1' in result.commands"
      - "'ip domain lookup vrf ansible source-interface Management1' in result.commands"
      - result.commands|length == 2

- name: verify change to vrf
  eos_system:
    lookup_source:
      - interface: Management1
        vrf: ansible
    timeout: 30
    provider: "{{ eapi }}"
  register: result

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

- 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_lookup_source.yaml"
