Map network drives for users
- Allows you to modify mapped network drives for individual users.
- Also support WebDAV endpoints in the UNC form.
Note
- 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.
- It is recommend to run this module with become or CredSSP when the remote path requires authentication.
- When using become or CredSSP, the task will have access to any local credentials stored in the user's vault.
- If become or CredSSP is not available, the username and password options can be used for the initial authentication but these are not persisted.
- WebDAV paths must have the WebDAV client feature installed for this module to map those paths. This is installed by default on desktop Windows editions but Windows Server hosts need to install the
WebDAV-Redirector
feature using :ref:`ansible.windows.win_feature <ansible.windows.win_feature_module>`.
.. seealso:: :ref:`community.windows.win_credential_module` The official documentation on the **community.windows.win_credential** module.
- name: Create a mapped drive under Z
community.windows.win_mapped_drive:
letter: Z
path: \\domain\appdata\accounting
- name: Delete any mapped drives under Z
community.windows.win_mapped_drive:
letter: Z
state: absent
- name: Only delete the mapped drive Z if the paths match (error is thrown otherwise)
community.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
community.windows.win_credential:
name: server
type: domain_password
username: username@DOMAIN
secret: Password01
state: present
- name: Create a mapped drive that requires authentication
community.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: yes
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
community.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
community.windows.win_mapped_drive:
letter: W
path: \\live.sysinternals.com@SSL\tools # https://live.sysinternals.com/tools
state: present
- Jordan Borean (@jborean93)