Issue with Ansible wait_for module - how to reliably check if the VM is up and running?

Solution 1:

Ansible 2.3

  tasks:
    - name: Pauses the workflow
      pause: minutes=5

    - name: Wait for port number 5986 to be available
      wait_for:
        host: {{ hostvars[item]['ansible_host'] }}
        port: 5986
        delay: 10
        state: started
      with_items:
        - VM-NO1
        - VM-NO2
      delegate_to: 127.0.0.1