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/40e42f15-7f40-4bc7-ab70-849906072a49n%40googlegroups.com.

Reply via email to