Saturday, December 31, 2016

Ansible Waiting for VM shutdown

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

Not Dead

This is site isn't dead, just slumbering. I'm thinking about moving a bunch of links that I've posted on another social media site here just to make them easier to find.