# Help using Win\_Copy Module From Windows Host To Windows Host

**URL:** <https://forum.ansible.com/t/help-using-win-copy-module-from-windows-host-to-windows-host/33798>\
**Category:** Ansible Project\
**Tags:** windows\
**Created:** [September 13, 2020, 9:50am UTC](https://forum.ansible.com/t/help-using-win-copy-module-from-windows-host-to-windows-host/33798 "2020-09-13T09:50:17Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![Paul\_Bull](https://avatars.discourse-cdn.com/v4/letter/p/f6c823/32.png) [@Paul\_Bull](https://forum.ansible.com/u/Paul_Bull)\
**Post date:** [September 13, 2020, 9:50am UTC](https://forum.ansible.com/t/help-using-win-copy-module-from-windows-host-to-windows-host/33798/1 "2020-09-13T09:50:17Z")

</div>

Hi Guys,

I would really welcome some help and input regarding the above in my lab.

I have a server with the file and the path is correct, as well as the username and pass.

This is the playbook:

# copy files

- hosts: windows

tasks:

- name: copy files from share  
win\_copy:  
src: \2019-ANSIBLE\c$\share\certnew.cer  
dest: \win19-ansible-2\c$\users\Administrator\Desktop\test\certnew.cer  
remote\_src: yes  
vars:  
ansible\_become\_user: Administrator  
ansible\_become\_pass: \*\*\*\*\*\*\*\*

And Error:

Using module file /usr/lib/python3/dist-packages/ansible/modules/windows/win\_copy.ps1  
Pipelining is enabled.  
\<[win19-ansible-2.ansible-ad.net](http://win19-ansible-2.ansible-ad.net)\> ESTABLISH WINRM CONNECTION FOR USER: [ansible@ANSIBLE-AD.NET](mailto:ansible@ANSIBLE-AD.NET) on PORT 5986 TO [win19-ansible-2.ansible-ad.net](http://win19-ansible-2.ansible-ad.net)  
EXEC (via pipeline wrapper)  
The full traceback is:  
Access is denied  
At line:305 char:15

- if (-not (Test-Path -LiteralPath $src)) {
- 

```auto

```

- CategoryInfo : PermissionDenied: (\2019-ANSIBLE\c$\share\certnew.cer:String) [Test-Path], UnauthorizedAccessException
- FullyQualifiedErrorId : ItemExistsUnauthorizedAccessError,Microsoft.PowerShell.Commands.TestPathCommand

ScriptStackTrace:  
at , : line 305

System.UnauthorizedAccessException: Access is denied —\> System.ComponentModel.Win32Exception: Access is denied  
— End of inner exception stack trace —  
at Microsoft.PowerShell.Commands.FileSystemProvider.ItemExists(String path, ErrorRecord& error)  
fatal: [[win19-ansible-2.ansible-ad.net](http://win19-ansible-2.ansible-ad.net)]: FAILED! =\> {  
“changed”: false,  
“dest”: “\\win19-ansible-2\c$\users\Administrator\Desktop\test\certnew.cer”,  
“msg”: “Unhandled exception while executing module: Access is denied”,  
“src”: “\\2019-ANSIBLE\c$\share\certnew.cer”  
}

Looking at the ansible documents examples :

I also tried :

# copy files

- hosts: windows

tasks:

- name: copy files from share  
win\_copy:  
src: C:\share\certnew.cer  
dest: C:\users\Administrator\Desktop\test\certnew.cer  
remote\_src: yes  
vars:  
ansible\_become\_user: Administrator  
ansible\_become\_pass: \*\*\*\*\*\*\*\*

and get:

fatal: [[win19-ansible-2.ansible-ad.net](http://win19-ansible-2.ansible-ad.net)]: FAILED! =\> {“changed”: false, “dest”: “C:\users\Administrator\Desktop\test\certnew.cer”, “msg”: “Cannot copy src file: ‘C:\share\certnew.cer’ as it does not exist”, “src”: “C:\share\certnew.cer”}

I’m stumped as the paths are correct and exist. Could anyone please help on how you copy from one windows host to another?. As well as from a share on one to another local path.

Much appreciated. Thank you

I tried that way above

---

<div class="post-metadata">

**Author:** ![jborean](https://sea1.discourse-cdn.com/ansible/user_avatar/forum.ansible.com/jborean/32/1525_2.png) [@jborean](https://forum.ansible.com/u/jborean)\
**Post date:** [September 14, 2020, 8:29pm UTC](https://forum.ansible.com/t/help-using-win-copy-module-from-windows-host-to-windows-host/33798/2 "2020-09-14T20:29:06Z")

</div>

You’ve set the become vars but you haven’t actually turned on become, have a read through [https://docs.ansible.com/ansible/latest/user\_guide/become.html#become-flags-for-windows](https://docs.ansible.com/ansible/latest/user_guide/become.html#become-flags-for-windows) especially the “copy a file from a fileshare with custom credentials” example.

If you are trying to copy a file from a remove UNC share to the local path of the Windows host, don’t use the UNC path for dest, just do ‘dest: C:\users\Administrator\Desktop\test\certnew.cer’. You still need the UNC path for src though as the src is how that process finds the file.

---

<div class="post-metadata">

**Author:** ![Paul\_Bull](https://avatars.discourse-cdn.com/v4/letter/p/f6c823/32.png) [@Paul\_Bull](https://forum.ansible.com/u/Paul_Bull)\
**Post date:** [September 14, 2020, 8:44pm UTC](https://forum.ansible.com/t/help-using-win-copy-module-from-windows-host-to-windows-host/33798/3 "2020-09-14T20:44:49Z")

</div>

I will take a look at this when i get home from work in the next few days and work this out.

I presume i do have the right module and win\_copy does allow Windows to windows copy then?. Only reason i ask is because of this in the documentation " The win\_copy module copies a file on the local box to remote windows locations." When i read that back it suggests to me the local box would be the Ansible host/management box?.

Or would in your opinion a different module be better for windows to windows?. For example the win\_shell with a copy-item command?.

Which in my case my ansible host is a Linux mint machine.

Again thank you for your response and taking the time out to reply and help!

---

<div class="post-metadata">

**Author:** ![jborean](https://sea1.discourse-cdn.com/ansible/user_avatar/forum.ansible.com/jborean/32/1525_2.png) [@jborean](https://forum.ansible.com/u/jborean)\
**Post date:** [September 15, 2020, 4:07am UTC](https://forum.ansible.com/t/help-using-win-copy-module-from-windows-host-to-windows-host/33798/4 "2020-09-15T04:07:45Z")

</div>

No it will work, by default it’s meant to copy files from the Ansible controller to the Windows host but with ‘remote\_src: yes’ it changes the context of src to be from the remote Windows host.

---

<div class="post-metadata">

**Author:** ![Paul\_Bull](https://avatars.discourse-cdn.com/v4/letter/p/f6c823/32.png) [@Paul\_Bull](https://forum.ansible.com/u/Paul_Bull)\
**Post date:** [September 15, 2020, 9:09pm UTC](https://forum.ansible.com/t/help-using-win-copy-module-from-windows-host-to-windows-host/33798/5 "2020-09-15T21:09:56Z")

</div>

I copied the example you gave me and it worked. Thanks for pointing me in the right direction and your help!
