# run a windows script once

**URL:** <https://forum.ansible.com/t/run-a-windows-script-once/18451>\
**Category:** Ansible Project\
**Tags:** windows\
**Created:** [June 9, 2015, 8:15pm UTC](https://forum.ansible.com/t/run-a-windows-script-once/18451 "2015-06-09T20:15:14Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![Andreas\_Roth](https://avatars.discourse-cdn.com/v4/letter/a/d78d45/32.png) [@Andreas\_Roth](https://forum.ansible.com/u/Andreas_Roth)\
**Post date:** [June 9, 2015, 8:15pm UTC](https://forum.ansible.com/t/run-a-windows-script-once/18451/1 "2015-06-09T20:15:14Z")

</div>

Hi all,

I'm trying to find a way to run a windows script just one time even if the  
playbook is excuted multiple times. For me it would be perfect to have some  
kind of "hook" file which defines if a script had already run.

On Linux I could use the creates argument. This does not seem to work with  
the "raw" module I'm using to trigger my installscript.

Here is my non-working playbook:

- name: "install vda on W2k12"  
&nbsp;&nbsp;hosts: tsasi01.bwlab.loc  
&nbsp;&nbsp;vars:  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;deploymentshare: \\myserver.domain.loc\installshare\  
&nbsp;&nbsp;tasks:  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;- name: Microsoft Visual C++ 2005 Redistributable  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;raw: '{{ deploymentshare  
}}applications\vcredisp2005-sp1-x86\install.cmd'  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;args:  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;creates: 'c:\test.txt'

Are there any good working workarounds for that?!

Thanks for your help in advance,

Andreas

---

<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:** [June 10, 2015, 7:40am UTC](https://forum.ansible.com/t/run-a-windows-script-once/18451/2 "2015-06-10T07:40:34Z")

</div>

Something I have done in the past is wrap the command I want to run inside a powershell script but have the powershell script run a test-path first so the command only gets run if the test-path is false. That's not great though as the script always reports 'changed', so a module would be better.

There is a win\_package module which hasn't yet been merged which I believe will run exe files that might be just what you need. I have not tried it but it looks worth a go.

You can use unmerged modules by copying them into your /etc/ansible/library

Hope this helps.

Jon
