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

- name: setup
  eos_config:
    lines:
      - no ip domain-list ansible.com
      - no ip domain-list redhat.com
    timeout: 30
    match: none
    provider: "{{ eapi }}"

- name: configure domain_list
  eos_system:
    domain_list:
      - ansible.com
      - redhat.com
    timeout: 30
    provider: "{{ eapi }}"
  register: result

- assert:
    that:
      - result.changed == true
      - "'ip domain-list ansible.com' in result.commands"
      - "'ip domain-list redhat.com' in result.commands"

- name: verify domain_list
  eos_system:
    domain_list:
      - ansible.com
      - redhat.com
    timeout: 30
    provider: "{{ eapi }}"
  register: result

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

- name: remove one entry
  eos_system:
    domain_list:
      - ansible.com
    timeout: 30
    provider: "{{ eapi }}"
  register: result

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

- name: verify remove one entry
  eos_system:
    domain_list:
      - ansible.com
    timeout: 30
    provider: "{{ eapi }}"
  register: result

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

- name: add one entry
  eos_system:
    domain_list:
      - ansible.com
      - redhat.com
    timeout: 30
    provider: "{{ eapi }}"
  register: result

- assert:
    that:
      - result.changed == true
      - "'ip domain-list redhat.com' in result.commands"

- name: verify add one entry
  eos_system:
    domain_list:
      - ansible.com
      - redhat.com
    timeout: 30
    provider: "{{ eapi }}"
  register: result

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

- name: add and remove one entry
  eos_system:
    domain_list:
      - ansible.com
      - eng.ansible.com
    timeout: 30
    provider: "{{ eapi }}"
  register: result

- assert:
    that:
      - result.changed == true
      - "'no ip domain-list redhat.com' in result.commands"
      - "'ip domain-list eng.ansible.com' in result.commands"
      - result.commands|length == 2

- name: verify add and remove one entry
  eos_system:
    domain_list:
      - ansible.com
      - eng.ansible.com
    timeout: 30
    provider: "{{ eapi }}"
  register: result

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

- name: teardown
  eos_config:
    lines:
      - no ip domain-list ansible.com
      - no ip domain-list redhat.com
      - no ip domain-list eng.ansible.com
    timeout: 30
    match: none
    provider: "{{ eapi }}"

- debug: msg="END eapi/set_domain_list.yaml"
