Note
This module is part of the ansible.windows collection (version 2.8.0).
You might already have this collection installed if you are using the ansible package. It is not included in ansible-core. To check whether it is installed, run ansible-galaxy collection list.
To install it, use: ansible-galaxy collection install ansible.windows.
To use it in a playbook, specify: ansible.windows.win_mapped_drive.
New in ansible.windows 2.7.0
Parameter | Comments |
|---|---|
letter string / required | The letter of the network path to map to. This letter must not already be in use with Windows. |
password string | The password for This is never saved with a mapped drive, use the ansible.windows.win_credential module to persist a username and password for a host. |
path path | The UNC path to map the drive to. If pointing to a WebDAV location this must still be in a UNC path in the format To specify a This is required if If If |
state string | If If Choices:
|
username string | The username that is used when testing the initial connection. This is never saved with a mapped drive, the ansible.windows.win_credential module to persist a username and password for a host. This is required if the mapped drive requires authentication with custom credentials and become, or CredSSP cannot be used. If become or CredSSP is used, any credentials saved with ansible.windows.win_credential will automatically be used instead. |
Note
WebDAV-Redirector feature using ansible.windows.win_feature.See also
Manages Windows Credentials in the Credential Manager.
- name: Create a mapped drive under Z
ansible.windows.win_mapped_drive:
letter: Z
path: \\domain\appdata\accounting
- name: Delete any mapped drives under Z
ansible.windows.win_mapped_drive:
letter: Z
state: absent
- name: Only delete the mapped drive Z if the paths match (error is thrown otherwise)
ansible.windows.win_mapped_drive:
letter: Z
path: \\domain\appdata\accounting
state: absent
- name: Create mapped drive with credentials and save the username and password
block:
- name: Save the network credentials required for the mapped drive
ansible.windows.win_credential:
name: server
type: domain_password
username: username@DOMAIN
secret: Password01
state: present
- name: Create a mapped drive that requires authentication
ansible.windows.win_mapped_drive:
letter: M
path: \\SERVER\C$
state: present
vars:
# become is required to save and retrieve the credentials in the tasks
ansible_become: true
ansible_become_method: runas
ansible_become_user: '{{ ansible_user }}'
ansible_become_pass: '{{ ansible_password }}'
- name: Create mapped drive with credentials that do not persist on the next logon
ansible.windows.win_mapped_drive:
letter: M
path: \\SERVER\C$
state: present
username: '{{ ansible_user }}'
password: '{{ ansible_password }}'
# This should only be required for Windows Server OS'
- name: Ensure WebDAV client feature is installed
ansible.windows.win_feature:
name: WebDAV-Redirector
state: present
register: webdav_feature
- name: Reboot after installing WebDAV client feature
ansible.windows.win_reboot:
when: webdav_feature.reboot_required
- name: Map the HTTPS WebDAV location
ansible.windows.win_mapped_drive:
letter: W
path: \\live.sysinternals.com@SSL\tools # https://live.sysinternals.com/tools
state: present
© 2012–2018 Michael DeHaan
© 2018–2025 Red Hat, Inc.
Licensed under the GNU General Public License version 3.
https://docs.ansible.com/ansible/latest/collections/ansible/windows/win_mapped_drive_module.html