# wait\_for a windows file

**URL:** <https://forum.ansible.com/t/wait-for-a-windows-file/20517>\
**Category:** Ansible Project\
**Tags:** windows\
**Created:** [February 10, 2016, 4:35pm UTC](https://forum.ansible.com/t/wait-for-a-windows-file/20517 "2016-02-10T16:35:04Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![Stavros](https://avatars.discourse-cdn.com/v4/letter/s/51bf81/32.png) [@Stavros](https://forum.ansible.com/u/Stavros)\
**Post date:** [February 10, 2016, 4:35pm UTC](https://forum.ansible.com/t/wait-for-a-windows-file/20517/1 "2016-02-10T16:35:04Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![j.r.hawkesworth](https://avatars.discourse-cdn.com/v4/letter/j/a3d4f5/32.png) [@j.r.hawkesworth](https://forum.ansible.com/u/j.r.hawkesworth)\
**Post date:** [February 11, 2016, 11:24am UTC](https://forum.ansible.com/t/wait-for-a-windows-file/20517/2 "2016-02-11T11:24:33Z")

</div>

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](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

---

<div class="post-metadata">

**Author:** ![Paul\_Farrington](https://avatars.discourse-cdn.com/v4/letter/p/94ad74/32.png) [@Paul\_Farrington](https://forum.ansible.com/u/Paul_Farrington)\
**Post date:** [June 8, 2017, 3:48pm UTC](https://forum.ansible.com/t/wait-for-a-windows-file/20517/3 "2017-06-08T15:48:18Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/ansible/original/1X/1882d9a01da5d8996a862359b0913cc568a39b84.svg) [@system](https://forum.ansible.com/u/system)\
**Post date:** [June 8, 2017, 4:53pm UTC](https://forum.ansible.com/t/wait-for-a-windows-file/20517/4 "2017-06-08T16:53:23Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![Stavros](https://avatars.discourse-cdn.com/v4/letter/s/51bf81/32.png) [@Stavros](https://forum.ansible.com/u/Stavros)\
**Post date:** [June 8, 2017, 6:22pm UTC](https://forum.ansible.com/t/wait-for-a-windows-file/20517/5 "2017-06-08T18:22:37Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![Paul\_Farrington](https://avatars.discourse-cdn.com/v4/letter/p/94ad74/32.png) [@Paul\_Farrington](https://forum.ansible.com/u/Paul_Farrington)\
**Post date:** [June 9, 2017, 7:50am UTC](https://forum.ansible.com/t/wait-for-a-windows-file/20517/6 "2017-06-09T07:50:44Z")

</div>

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
