---
- block:
  - name: Check connection status on {{ item }}
    wait_for:
      port: 22                                                                                                                                       
      host: "{{ item }}"
      state: present
      timeout: 30
        #    ignore_errors: yes
    register: failed_vms
  rescue:
    - name: Stop faulty virtual machine
      virt:
        name: "{{ item }}"
        state: shutdown

    - name: Wait for shutdown
      wait_for:
        timeout: 10

    - name: Start virtual machine
      virt:
        name: "{{ item }}"
        state: running
