wait_for a windows file

Hi,

I use the wait_for in a playbook in order to wait until a file is present, but this doesn’t work, e.g.

  • name: Wait for remote host
    wait_for: host={{ floating_ip }} path=“C:\Temp\status.txt” state=present

When I use the wait_for module for the winrm port, then it works fine:

  • name: Wait for remote host
    wait_for: host={{ floating_ip }} port=5986 state=started

Any idea, how to wait in Windows for a file until it is present?

Thanks in advance!

KR,
Stavros

Hmm wait_for is a python module.

waiting for the port will work fine as that will presumably be happening on the ansible controller, rather than remotely on the machine you are trying to access.

If only waiting for a file will do then you could try using the fetch module to pull the file back you want to collect (fetch runs against windows hosts), then examine the file on the ansible controller.
Would likely need to be wrapped in a block / rescue / always block - see http://docs.ansible.com/ansible/playbooks_blocks.html, and you might need to start off by waiting for a certain amount of time to avoid having to have multiple blocks to retry, but it might be enough to get you going.

Hope this helps,

Jon

Stavros, did you ever get this resolved as i have this exact issue now.

We’ve got a win_wait_for module on the roadmap for 2.4. Meantime, a win_shell task with a one-liner while loop using Test-Path and Start-Sleep should do the trick.

-Matt

Paul, I did resolve it by using the following workaround:

First of all I searched for a Windows Service in the target host that was not used (it was in the manual status) and in case it would be started, then it should use a certain port for listening. With Ansible:

  • I scheduled a Windows job that was “looking for the condition to fulfill” on the target host. The job was running every couple of minutes. Once it was so far, the scheduled job was going to start a windows service, which was listening to a certain port. After the Windows service has started, the scheduled job had finally to delete “itself” from the scheduled jobs on the target host
  • I was using this port number of the Windows service in the wait_for

My Ansible playbook had to reboot the target host anyway at the end. The Windows service I “misused” for the “wait_for” was not running after the reboot, so everything was “clean” again.

Hope it helps,
Stavros

Hi Stavros,

Thanks for the reply, i came to a similar conclusion which i am working on at the moment. I am deploying via a VMware customization spec and need to wait for it to complete so i am going to use the powershell Listen-Port module and fire that up on a RunOnce. Then ill use wait_for to detect the open port…

If i dont get anywhere, ill give your process a shot.

Thanks!
Paul