# Ansible copy file module to Windows host fails

**URL:** <https://forum.ansible.com/t/ansible-copy-file-module-to-windows-host-fails/17076>\
**Category:** Ansible Project\
**Tags:** windows\
**Created:** [December 16, 2014, 2:42pm UTC](https://forum.ansible.com/t/ansible-copy-file-module-to-windows-host-fails/17076 "2014-12-16T14:42:22Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![Jeff\_Liu](https://avatars.discourse-cdn.com/v4/letter/j/d6d6ee/32.png) [@Jeff\_Liu](https://forum.ansible.com/u/Jeff_Liu)\
**Post date:** [December 16, 2014, 2:42pm UTC](https://forum.ansible.com/t/ansible-copy-file-module-to-windows-host-fails/17076/1 "2014-12-16T14:42:22Z")

</div>

Hi All,

I’m running Ansible 1.8.2 on a CentOS 6.6 server.

I’m trying to copy a file to a windows host, but the copy module fails. The weird thing is that I do see that it does PUT the file over to the remote windows host, but it fails when it tries to execute the powershell to rename the file to the destination directory.  
If I abort the command before it removes the temporary files I can confirm the remote “source” file is the actual file. It looks like the failure is on the remote end to rename the file. Any ideas if this can be fixed? It’s a rather important feature for me to be able to distribute powershell scripts for remote execution.

Thanks!

[jklee@l99app09 poc]$ cat testcopy.yml

# ansible-playbook -i hosts testcopy.yml --extra-vars=“source=‘list-installed-programs.ps1’ d=‘C:\Users\jklee\list-installed-programs.ps1’”

---

<div class="post-metadata">

**Author:** ![sivel](https://sea1.discourse-cdn.com/ansible/user_avatar/forum.ansible.com/sivel/32/1198_2.png) [@sivel](https://forum.ansible.com/u/sivel)\
**Post date:** [December 17, 2014, 1:28pm UTC](https://forum.ansible.com/t/ansible-copy-file-module-to-windows-host-fails/17076/2 "2014-12-17T13:28:21Z")

</div>

Ansible 1.8.x does not support the copy module for windows hosts. A win\_copy module was just merged into devel (which will become 1.9):

[https://github.com/ansible/ansible-modules-core/pull/384](https://github.com/ansible/ansible-modules-core/pull/384)  
[https://github.com/ansible/ansible/pull/9611](https://github.com/ansible/ansible/pull/9611)

---

<div class="post-metadata">

**Author:** ![Jeff\_Liu](https://avatars.discourse-cdn.com/v4/letter/j/d6d6ee/32.png) [@Jeff\_Liu](https://forum.ansible.com/u/Jeff_Liu)\
**Post date:** [December 20, 2014, 5:03pm UTC](https://forum.ansible.com/t/ansible-copy-file-module-to-windows-host-fails/17076/3 "2014-12-20T17:03:54Z")

</div>

Thanks. I found out that win\_copy has a pull request about to be merged into 1.9

I also found a resource for copy.ps1 which works – I don’t need all the bells and whistles and a rudimentary copy function is all that’s needed for now.  
Although, for the purposes of just running a powershell script, the script module works well too.

Thanks again!

---

<div class="post-metadata">

**Author:** ![Jaime\_Banda](https://avatars.discourse-cdn.com/v4/letter/j/90ced4/32.png) [@Jaime\_Banda](https://forum.ansible.com/u/Jaime_Banda)\
**Post date:** [January 27, 2015, 6:24pm UTC](https://forum.ansible.com/t/ansible-copy-file-module-to-windows-host-fails/17076/4 "2015-01-27T18:24:05Z")

</div>

Can you share your code that works an how did you did it?

---

<div class="post-metadata">

**Author:** ![Jeff\_Liu](https://avatars.discourse-cdn.com/v4/letter/j/d6d6ee/32.png) [@Jeff\_Liu](https://forum.ansible.com/u/Jeff_Liu)\
**Post date:** [January 27, 2015, 7:45pm UTC](https://forum.ansible.com/t/ansible-copy-file-module-to-windows-host-fails/17076/5 "2015-01-27T19:45:37Z")

</div>

References:  
[https://groups.google.com/forum/#!topic/ansible-devel/Jl5qP73CiKo](https://groups.google.com/forum/#!topic/ansible-devel/Jl5qP73CiKo)

Place this copy.ps1 to /usr/lib/python2.6/site-packages/ansible/modules/core/windows/copy.ps1

# [https://gist.github.com/tkinz27/fd92ba9af0e0309614ee](https://gist.github.com/tkinz27/fd92ba9af0e0309614ee)

Tho it’s probably not needed if you can use the win\_url module or if you just want to run a powershell script, the script module works too.
