# facing the problem in mapping network drive

**URL:** <https://forum.ansible.com/t/facing-the-problem-in-mapping-network-drive/32931>\
**Category:** Ansible Project\
**Tags:** windows\
**Created:** [May 14, 2020, 10:49am UTC](https://forum.ansible.com/t/facing-the-problem-in-mapping-network-drive/32931 "2020-05-14T10:49:01Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![mahesh\_g\_o](https://avatars.discourse-cdn.com/v4/letter/m/e9bcb4/32.png) [@mahesh\_g\_o](https://forum.ansible.com/u/mahesh_g_o)\
**Post date:** [May 14, 2020, 10:49am UTC](https://forum.ansible.com/t/facing-the-problem-in-mapping-network-drive/32931/1 "2020-05-14T10:49:01Z")

</div>

Hi ,

help is appreciated

playbook:mount.yml

- hosts: localhost  
gather\_facts: false  
vars\_files:
- /etc/ansible/group\_vars/host\_vars  
tasks:
- name: create a mapped drive under Z  
win\_mapped\_drive:  
letter: Z  
path: \10.237.163.116\test  
username: test  
password: Password123

host\_vars:  
windows machine details:

ip: “10.234.224.199”  
username: “Administrator”  
password: “netapp”  
ansible\_connection: “winrm”  
ansible\_winrm\_server\_cert\_validation: “ignore”

i am getting below error when run the playbook:  
fatal: [localhost]: UNREACHABLE! =\> {“changed”: false, “msg”: “ssl: auth method ssl requires a username”, “unreachable”: true}

---

<div class="post-metadata">

**Author:** ![Luca\_remix\_tj\_Lorenz](https://avatars.discourse-cdn.com/v4/letter/l/ea666f/32.png) [@Luca\_remix\_tj\_Lorenz](https://forum.ansible.com/u/Luca_remix_tj_Lorenz)\
**Post date:** [May 14, 2020, 11:01am UTC](https://forum.ansible.com/t/facing-the-problem-in-mapping-network-drive/32931/2 "2020-05-14T11:01:26Z")

</div>

Hello,

---

<div class="post-metadata">

**Author:** ![mahesh\_g\_o](https://avatars.discourse-cdn.com/v4/letter/m/e9bcb4/32.png) [@mahesh\_g\_o](https://forum.ansible.com/u/mahesh_g_o)\
**Post date:** [May 14, 2020, 11:17am UTC](https://forum.ansible.com/t/facing-the-problem-in-mapping-network-drive/32931/3 "2020-05-14T11:17:26Z")

</div>

I am setting the username and password:  
i have a volume name “test” in my storage box and i want to map it windows machine:

details in host\_vars are my machine details:

volume details:

letter: Z  
path: \10.237.163.116\test  
username: test  
password: Password123

i am expecting the playbook use host\_vars file to login to windows machine and mount the volume in z drive.

---

<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:** [May 14, 2020, 9:06pm UTC](https://forum.ansible.com/t/facing-the-problem-in-mapping-network-drive/32931/4 "2020-05-14T21:06:13Z")

</div>

The error you have is nothing to do with mapped drives but that Ansible is unable to authenticate itself over the WinRM connection. YOu need to set ansible\_user and ansible\_password for Ansible to use as the connection credentials.

Also please note that while you can map a network drive using win\_mapped\_drive in Ansible, you cannot use that mapped drive in Ansible tasks. That mapping is just for interactive logons. If you want to access files from a network path in Ansible you need to use the UNC path and potentially use become to add outbound creds to your process. We have an example of that here [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).

---

<div class="post-metadata">

**Author:** ![mahesh\_g\_o](https://avatars.discourse-cdn.com/v4/letter/m/e9bcb4/32.png) [@mahesh\_g\_o](https://forum.ansible.com/u/mahesh_g_o)\
**Post date:** [May 15, 2020, 8:01am UTC](https://forum.ansible.com/t/facing-the-problem-in-mapping-network-drive/32931/5 "2020-05-15T08:01:43Z")

</div>

Thanks Jordan,

I used become in my playbook.

- hosts: [win]  
gather\_facts: false  
tasks:
- name: create a mapped drive  
win\_mapped\_drive:  
state: present  
letter: D  
path: \10.237.163.116\test

vars:

# become is required to save and retrieve the credentials in the tasks

ansible\_become: yes  
ansible\_become\_method: runas  
ansible\_become\_user: test  
ansible\_become\_pass: password@123  
ansible\_become\_flags: logon\_type=new\_credentials logon\_flags=netcredentials\_only

Playbook is running without any errors.

But i am not seeing the network drive in my windows OS.  
net use:  
Unavailable T: \10.237.163.116\test Microsoft Windows Network

what is that i am missing here. what is the solution to map the network drive.

---

<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:** [May 15, 2020, 8:00pm UTC](https://forum.ansible.com/t/facing-the-problem-in-mapping-network-drive/32931/6 "2020-05-15T20:00:55Z")

</div>

So the drive mapping is present but Windows is unable to map the drive on logon. You can use the win\_credential [1] to store a credential that Windows will use for mapped drives. There’s even an example of this in the win\_mapped\_drive [2] docs. If you are running the net use command through Ansible and expecting to see that mapped drive available then you are out of luck. Mapped drives are only for use with interactive logons and not for use in Ansible, Ansible can only manage the mappings but not use them.

[1] [https://docs.ansible.com/ansible/latest/modules/win\_credential\_module.html](https://docs.ansible.com/ansible/latest/modules/win_credential_module.html)  
[2] [https://docs.ansible.com/ansible/latest/modules/win\_mapped\_drive\_module.html](https://docs.ansible.com/ansible/latest/modules/win_mapped_drive_module.html)

---

<div class="post-metadata">

**Author:** ![mahesh\_g\_o](https://avatars.discourse-cdn.com/v4/letter/m/e9bcb4/32.png) [@mahesh\_g\_o](https://forum.ansible.com/u/mahesh_g_o)\
**Post date:** [May 26, 2020, 8:19am UTC](https://forum.ansible.com/t/facing-the-problem-in-mapping-network-drive/32931/7 "2020-05-26T08:19:32Z")

</div>

Hi Jordan,

I tried the below playbook to store the credential that Windows will use for mapped drives. But it is throwing the below error :

- hosts: [win]  
gather\_facts: false  
tasks:
- name: Save the network credentials required for the mapped drive  
win\_credential:  
name: 10.224.233.199 -----\> windows machine IP  
type: domain\_password  
state: present  
#persistence: local  
#secret\_format: text  
#update\_secret: always  
username: Administrator-----\> windows machine username  
secret: opteamix------\> windows machine password  
become: yes  
become\_method: runas

vars:

# become is required to save and retrieve the credentials in the tasks

ansible\_become\_user: apple ----- username of the drive to be mapped.  
ansible\_become\_pass: barharbour -----password of the drive to be mapped.  
ansible\_become\_flags: logon\_type=new\_credentials logon\_flags=netcredentials\_only

fatal: [10.234.224.199]: FAILED! =\> {  
“changed”: false,  
“msg”: “Unhandled exception while executing module: Exception calling "GetCredential" with "2" argument(s): "Failed to access the user’s credential store, run the module with become"”

Thanks,  
Mahesh

---

<div class="post-metadata">

**Author:** ![David\_Foley](https://avatars.discourse-cdn.com/v4/letter/d/9e8a1a/32.png) [@David\_Foley](https://forum.ansible.com/u/David_Foley)\
**Post date:** [May 26, 2020, 8:44am UTC](https://forum.ansible.com/t/facing-the-problem-in-mapping-network-drive/32931/8 "2020-05-26T08:44:11Z")

</div>

Hi,

It may be easier to use PowerShell within an Ansible caller.

[https://docs.microsoft.com/en-us/powershell/module/microsoft.powershell.management/new-psdrive?view=powershell-7](https://docs.microsoft.com/en-us/powershell/module/microsoft.powershell.management/new-psdrive?view=powershell-7)
