Retry SSH connection?

I have a complex playbook that will provision a CentOS VM on a XenServer pool from scratch and then configure the VM according to its roles. It works very well (and I’m very impressed with Ansible) except for one part. As XenServer installs the VM and OS (via a delegate_to call in the Task) it takes time and the VM is not yet online. The next step in my Ansible script tries to connect to the new and still offline VM and promptly fails. Neither ‘async’ nor ‘do-until’ have worked. It always fails because Ansible cannot connect via SSH to the newly spun up VM.

My question is, how can I get this task to keep trying to connect? I could not find anything in the docs or Google to suggest an approach.

Thank you,
Aaron

DevOps Blog: http://www.sharknet.us

This is a great place to use the “wait_for” module to wait for the port to become open.

Michael,

Thank you. Looks like you already anticipated the need for this. Sorry I missed it.

It worked. For the sake of others, here is the statement that accomplished the task. It wouldn’t work without the “local_action” part. I put this in my “main.yml” under the “vm” role.

[VM creation tasks…]

  • name: Wait for the Kickstart install to complete and the VM to reboot
    local_action: wait_for host={{ vm_hostname }} port=22 delay=30 timeout=1200 state=started

  • name: Now configure the VM…

–Aaron
DevOps Blog: http://www.sharknet.us