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

- name: setup
  ios_config:
    lines:
      - no ip domain lookup source-interface
      - vrf definition ansible
    match: none
    authorize: yes

- name: configure lookup_source
  ios_system:
    lookup_source: Loopback10
    authorize: yes
  register: result

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

- name: verify lookup_source
  ios_system:
    lookup_source: Loopback10
    authorize: yes
  register: result

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

- name: Disable lookup_source
  ios_system:
    lookup_enabled: False
    authorize: yes
  register: result

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

- name: Disable lookup_source
  ios_system:
    lookup_enabled: True
    authorize: yes
  register: result

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

#- name: change to vrf
#  ios_system:
#    lookup_source:
#      - interface: Loopback10
#        vrf: ansible
#    authorize: yes
#    provider: "{{ cli }}"
#  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
#  ios_system:
#    lookup_source:
#      - interface: Management1
#        vrf: ansible
#    authorize: yes
#    provider: "{{ cli }}"
#  register: result
#
#- assert:
#    that:
#      - result.changed == false

- name: teardown
  ios_config:
    lines:
      - no ip domain lookup source-interface
      - no vrf definition ansible
    match: none
    authorize: yes
  ignore_errors: yes
# FIXME: Not sure why this is failing with msg": "no vrf definition ansible\r\n% IPv4 and IPv6 addresses from all interfaces in VRF ansible have been removed\r\nfoo(config)#", rc:1

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