I've been using Ansible for the past 8 months for a web application. Recently I needed a way to wait for the VM to shutdown. The solution I ended up using is the following. Essentially it's a script that greps the virtual machine list until the virtual machine name does not show up.
- name: wait for the VM to shutdown
shell: while [[ `virsh list | grep {{ vmimage }} ` ]]; do sleep 1; done; exit 0
poll: 3
If I want to start a VM and wait for it to become ready, I use a wait_for to wait for ssh to respond. There's probably a better way to do this.
- name: wait for vm ssh to start
wait_for: host={{ vmhostname}} port=22 state=present delay=10 connect_timeout=3