Win_robocopy getting "access denied" error

Hi.

I am trying to copy a directory structure from \\server1\share1\folder1 to c:\folder1 using win_robocopy. Here is a sample of my task.

 - name: "copy directory from share"
   win_robocopy:
     src: '\\server1\share1\folder1'
     dest:  'c:\folder1'
     flags: '/S /E /copy:DAT /mt /z'
   become: true
   become_user: "{{ ansible_user }}"

When I log into the machine as ansible_user, I do not need to provide the credentials to access \\server1\share1\folder1 using File Explorer. However, when I run the playbook, i get an
Access Denied error.

Help.

Thank you in advance.

ansible [core 2.16.14]

What authentication method are you using for WinRM? The method you select needs to support credential delegation to use UNC paths. This is not an Ansible problem but a side effect of WinRM and Windows. It can be replicated in a remote PSSession using powershell commandlets.

You are using become but with no become password. Set the ansible_become_password variable to {{ ansible_password }} (or whatever var contains the password. Keep in mind this is a variable not a task option so needs to be set under the vars key.

Here is my solution to the same problem:
The problem was something with that you need an extra login for windows hosts because how windows uses logons or whatever. Dont remember.

  become: true
  become_method: runas
  become_flags: logon_type=new_credentials logon_flags=netcredentials_only
  vars:
    ansible_become_user: '{{ vaulted_ansible_username }}'
    ansible_become_pass: '{{ vaulted_ansible_password }}'
  no_log: true

Thank you all for all the info. I ended using @it-pappa 's recommendation.