---
- name: Get VM network info
  virt_util:
      command: 'domain_xml_devices'
      domain: "{{ vm_name }}"
      device_class: 'interface'
  register: vm_network_info
  tags: skip_ansible_lint

- name: Reset network list
  set_fact:
      network_list: []

- name: Create network list
  set_fact:
      network_list: "{{ network_list + [network_name] }}"
  vars:
      network_name: "{{ item.source.network }}"
  with_items: "{{ vm_network_info.devices }}"

- name: Get VM static IPs
  shell: virsh net-dumpxml {{ item }} | grep {{ vm_name }}
  ignore_errors: yes
  register: vm_static_ips
  with_items: "{{ network_list }}"

- include_tasks: remove_static_ips.yml
  vars:
      network_name: "{{ vm_static_result.item }}"
      ips_records: "{{ vm_static_result.stdout_lines }}"
  with_items: "{{ vm_static_ips.results }}"
  when: item.rc == 0
  loop_control:
      loop_var: vm_static_result

- name: remove all snapshots
  include_tasks: remove_snapshots.yml

- name: remove vm
  include_tasks: remove_vm.yml
---
- name: Get VM network info
  virt_util:
      command: 'domain_xml_devices'
      domain: "{{ vm_name }}"
      device_class: 'interface'
  register: vm_network_info
  tags: skip_ansible_lint

- name: Reset network list
  set_fact:
      network_list: []

- name: Create network list
  set_fact:
      network_list: "{{ network_list + [network_name] }}"
  vars:
      network_name: "{{ item.source.network }}"
  with_items: "{{ vm_network_info.devices }}"

- name: Get VM static IPs
  shell: virsh net-dumpxml {{ item }} | grep {{ vm_name }}
  ignore_errors: yes
  register: vm_static_ips
  with_items: "{{ network_list }}"

- include_tasks: remove_static_ips.yml
  vars:
      network_name: "{{ vm_static_result.item }}"
      ips_records: "{{ vm_static_result.stdout_lines }}"
  loop: "{{ vm_static_ips.results }}"
  when: vm_static_result.rc == 0
  loop_control:
      loop_var: vm_static_result

- name: remove all snapshots
  include_tasks: remove_snapshots.yml

- name: remove vm
  include_tasks: remove_vm.yml
Fix remove node in virsh plugin
Fix remove node in virsh plugin

Change when statement when including the remove_static_ips.yml file
to use the new loop instead of deprecated with_items and change use
of item variable to the defined loop_var.

RHOSINFRA-2328

Change-Id: I120cecd8244fd2c49206d38c8080055a59c847a1
