The network mapping disk generated by win_mapped_drive is not available

My Syntax is here
  tasks:
  - name: create a mapped drive under Z
    win_mapped_drive:
      letter: Z
      path: \192.168.227.181.0.0\pys
      username: administrator
      password: Test123456
      
  - name: copy file
    win_copy:
      src: Z:\
      dest: C:\tools
      remote_src: True

The execution result:

In the latest docs for win_mapped_drive (https://docs.ansible.com/ansible/devel/modules/win_mapped_drive_module.html) there is a note that says

You cannot use this module to access a mapped drive in another Ansible task, drives mapped with this module are only accessible when logging in interactively with the user through the console or RDP.

Ultimately due to the security model of Windows this is not possible and as you can see the Z: drive has been mapped to the path you specified when you logged on locally. We’ve documented some of these limitations here https://groups.google.com/forum/#!topic/ansible-project/5uk0-ki7zT8 but ultimately you have a few options;

  • Use become on the task and become the user you want to connect with (http://docs.ansible.com/ansible/devel/user_guide/become.html#become-and-windows). When you use become those credentials are available on that process to connect to a remote host

  • Use CredSSP or Kerberos with credential delegation enabled and the user will be able to access a network path with the connection user’s variables

  • Use a module like win_psexec and run it with the user’s credentials

  • Use a scheduled task to run the command with the user’s credentials

There

Thanks

Jordan