# win\_mapped\_drive fails with become(runas) and ansible\_become\_pass var defined

**URL:** <https://forum.ansible.com/t/win-mapped-drive-fails-with-become-runas-and-ansible-become-pass-var-defined/33203>\
**Category:** Ansible Project\
**Tags:** windows\
**Created:** [June 17, 2020, 3:22pm UTC](https://forum.ansible.com/t/win-mapped-drive-fails-with-become-runas-and-ansible-become-pass-var-defined/33203 "2020-06-17T15:22:03Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![viten](https://avatars.discourse-cdn.com/v4/letter/v/e47774/32.png) [@viten](https://forum.ansible.com/u/viten)\
**Post date:** [June 17, 2020, 3:22pm UTC](https://forum.ansible.com/t/win-mapped-drive-fails-with-become-runas-and-ansible-become-pass-var-defined/33203/1 "2020-06-17T15:22:03Z")

</div>

Hi everyone,

I’m trying to mount smb share on windows host (win10 pro) that requires authentication using **win\_mapped\_drive/win\_credential**

Here is the playbook sample (based on docs example)

`

- name: Create mapped drive with credentials and save the username and password  
block:

- name: Save the network credentials required for the mapped drive  
win\_credential:  
name: 10.0.20.1  
type: domain\_password  
username: DOMAIN\admin  
secret: password  
state: present

- name: Create a mapped drive that requires authentication  
win\_mapped\_drive:  
letter: M  
path: \10.0.20.1\myshare1  
state: present  
vars:

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

ansible\_become: yes  
ansible\_become\_method: runas  
ansible\_become\_user: ‘{{ ansible\_user }}’  
ansible\_become\_pass: ‘{{ ansible\_password }}’

`

But the issue is:

- if **ansible\_become\_pass** variable is set **win\_mapped\_drive** task fails:

`  
The full traceback is:  
Exception calling “Invoke” with “2” argument(s): “Failed to map M: to ‘\10.0.20.1\myshare1’ with WNetAddConnection2W() (The specified network password is not correct, Win32ErrorCode 86)”  
At line:420 char:17

- … $add\_method.Invoke($null, [Object]@($letter\_root, $path …
- 

```auto

```

- CategoryInfo : NotSpecified: (🙂 , ParentContainsErrorRecordException
- FullyQualifiedErrorId : Win32Exception

ScriptStackTrace:  
at , : line 420  
fatal: [win1]: FAILED! =\> {  
“changed”: false,  
“msg”: “Unhandled exception while executing module: Exception calling "Invoke" with "2" argument(s): "Failed to map M: to ‘\\10.0.20.1\myshare1’ with WNetAddConnection2W() (The specified network password is not correct, Win32ErrorCode 86)"”  
}

`

- if **ansible\_become\_pass** variable is unset (or empty string) - everything works perfectly

So, AFAIK in 2.8+ become can work without password, as the docs say:  
[https://docs.ansible.com/ansible/latest/user\_guide/become.html#become-without-setting-a-password](https://docs.ansible.com/ansible/latest/user_guide/become.html#become-without-setting-a-password)

But my assumtions were, that with password defined it should wark just fine

My ansible version is - ansible 2.9.9

Windows host’s account i’m using is local admin

Can someone help me to debug the issue, it’s probably me missusing the module or some sort of admin account missconfiguration (e.g. disabled priveledges mb), but no ideas left for me to prove it, thanks in advance.

---

<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:** [June 18, 2020, 11:59pm UTC](https://forum.ansible.com/t/win-mapped-drive-fails-with-become-runas-and-ansible-become-pass-var-defined/33203/2 "2020-06-18T23:59:26Z")

</div>

There’s been a recent issue on this problem [https://github.com/ansible-collections/community.windows/issues/96](https://github.com/ansible-collections/community.windows/issues/96). I can’t say I’ve experienced this problem personally as if you have a credential Windows should be using that to connect to the network path. Are you potentially on a newer build of Windows 10?

---

<div class="post-metadata">

**Author:** ![viten](https://avatars.discourse-cdn.com/v4/letter/v/e47774/32.png) [@viten](https://forum.ansible.com/u/viten)\
**Post date:** [June 19, 2020, 2:58pm UTC](https://forum.ansible.com/t/win-mapped-drive-fails-with-become-runas-and-ansible-become-pass-var-defined/33203/3 "2020-06-19T14:58:00Z")

</div>

I’ve build the image for openstack via [https://github.com/cloudbase/windows-openstack-imaging-tools](https://github.com/cloudbase/windows-openstack-imaging-tools)  
It’s Win10 Pro N

`  
PS C:\Users\Admin\> [System.Environment]::OSVersion.Version  
Major Minor Build Revision

* * *

10 0 19041 0  
`

The issue you’ve linked seems relevant, but in my case even `net use` doesn’t work when `ansible_become_pass` is set, i’ve found out that that when i use bacome w/o password all steps are executed in the same logon session (i’ve check it with subsequent win\_whoami),  
when become is used with password defined logon session ids are different, but it should work, cause `cmdkey` sees the target’s creds.

So workarounds for me:

1. delete ansible\_become\_pass var
2. define usename/password (for initial connection) for ansible\_become\_pass.

And the one more strange thing is that Error code may vary, sometimes it’s 86, sometimes it’s - “The user name or password is incorrect, Win32ErrorCode 1326” - this one is far beyond my understanding.

My initial task was to mount share for java app which works via nssm under Local System Account privelegies (i guess it’s the same as runas + SYSTEM user), so for that purpose (thx to your blog’s article) i’ve used “global” scope mapping.

---

<div class="post-metadata">

**Author:** ![viten](https://avatars.discourse-cdn.com/v4/letter/v/e47774/32.png) [@viten](https://forum.ansible.com/u/viten)\
**Post date:** [June 26, 2020, 6:49am UTC](https://forum.ansible.com/t/win-mapped-drive-fails-with-become-runas-and-ansible-become-pass-var-defined/33203/4 "2020-06-26T06:49:44Z")

</div>

Sorry, the 2nd one was incorrect:

So workarounds for me:

1. delete `ansible_become_pass` var
2. define usename/password (for initial connection) for `win_mapped_drive`

пятница, 19 июня 2020 г. в 17:58:01 UTC+3, [viten...@gmail.com](mailto:viten...@gmail.com):
