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.

On Tuesday, September 15, 2020 at 6:44:49 AM UTC+10 [email protected] wrote:

> 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!
>
> On Monday, September 14, 2020 at 9:29:06 PM UTC+1 [email protected] wrote:
>
>> 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
>>  
>> 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.
>>
>> On Sunday, September 13, 2020 at 7:50:17 PM UTC+10 [email protected] 
>> wrote:
>>
>>>
>>> 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> ESTABLISH WINRM CONNECTION FOR USER: 
>>> [email protected] on PORT 5986 TO 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)) {
>>> +               ~~~~~~~~~~~~~~~~~~~~~~~~~~~
>>>     + CategoryInfo          : PermissionDenied: 
>>> (\\2019-ANSIBLE\c$\share\certnew.cer:String) [Test-Path], 
>>> UnauthorizedAccessException
>>>     + FullyQualifiedErrorId : 
>>> ItemExistsUnauthorizedAccessError,Microsoft.PowerShell.Commands.TestPathCommand
>>>
>>> ScriptStackTrace:
>>> at <ScriptBlock>, <No file>: 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]: 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]: 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
>>>
>>

-- 
You received this message because you are subscribed to the Google Groups 
"Ansible Project" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/ansible-project/db90443a-8d1f-4c4a-8f65-c1e427716f18n%40googlegroups.com.

Reply via email to