community.windows.win_mapped_drive (2.2.0) — module

Map network drives for users

Authors: Jordan Borean (@jborean93)

Install collection

Install with ansible-galaxy collection install community.windows:==2.2.0


Add to requirements.yml

  collections:
    - name: community.windows
      version: 2.2.0

Description

Allows you to modify mapped network drives for individual users.

Also support WebDAV endpoints in the UNC form.

Usage examples

  • Success
    Steampunk Spotter scan finished with no errors, warnings or hints.
- name: Create a mapped drive under Z
  community.windows.win_mapped_drive:
    letter: Z
    path: \\domain\appdata\accounting
  • Success
    Steampunk Spotter scan finished with no errors, warnings or hints.
- name: Delete any mapped drives under Z
  community.windows.win_mapped_drive:
    letter: Z
    state: absent
  • Success
    Steampunk Spotter scan finished with no errors, warnings or hints.
- 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
  • Success
    Steampunk Spotter scan finished with no errors, warnings or hints.
- 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 }}'
  • Success
    Steampunk Spotter scan finished with no errors, warnings or hints.
- 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 }}'
  • Success
    Steampunk Spotter scan finished with no errors, warnings or hints.
# 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
  • Success
    Steampunk Spotter scan finished with no errors, warnings or hints.
- name: Reboot after installing WebDAV client feature
  ansible.windows.win_reboot:
  when: webdav_feature.reboot_required
  • Success
    Steampunk Spotter scan finished with no errors, warnings or hints.
- 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

Inputs

    
path:
    description:
    - 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
      C(\\hostname\path) and not a URL, see examples for more details.
    - To specify a C(https) WebDAV path, add C(@SSL) after the hostname. To specify a
      custom WebDAV port add C(@<port num>) after the C(@SSL) or hostname portion of the
      UNC path, e.g. C(\\server@SSL@1234) or C(\\server@1234).
    - This is required if C(state=present).
    - If C(state=absent) and I(path) is not set, the module will delete the mapped drive
      regardless of the target.
    - If C(state=absent) and the I(path) is set, the module will throw an error if path
      does not match the target of the mapped drive.
    type: path

state:
    choices:
    - absent
    - present
    default: present
    description:
    - If C(present) will ensure the mapped drive exists.
    - If C(absent) will ensure the mapped drive does not exist.
    type: str

letter:
    description:
    - The letter of the network path to map to.
    - This letter must not already be in use with Windows.
    required: true
    type: str

password:
    description:
    - The password for C(username) that is used when testing the initial connection.
    - This is never saved with a mapped drive, use the M(community.windows.win_credential)
      module to persist a username and password for a host.
    type: str

username:
    description:
    - The username that is used when testing the initial connection.
    - This is never saved with a mapped drive, the M(community.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 M(community.windows.win_credential)
      will automatically be used instead.
    type: str

See also