Search code examples
windowspowershellansiblesubst

Ansible to SUBST a drive machine-wide


I've set up Ansible to connect to a Windows Server 2019 using WinRM certificate method. I need to map D drive to simply mirror C. With SUBST I can do SUBST D: C:\ but...

  • When I run the command with Ansible using win_shell Remote Desktop does not show the drive.
  • The opposite is also true: when I run the command with Remote Desktop, Ansible's shell does not see the new D drive.
  • I tried using registry tricks to make the mapping persist, and after rebooting I can see the drive in File Explorer with Remote Desktop but neither PowerShell nor Ansible's win_shell see it.

How can I map C to D machine-wide using an Ansible playbook?


Solution

  • The registry value for the drive was missing \??\ prefix. Everything works correctly with the right registry value. For the record, this is the ansible task I ended up with:

        - name: Map D drive to C.
          ansible.windows.win_regedit:
            path: HKLM:\SYSTEM\CurrentControlSet\Control\Session Manager\DOS Devices
            name: "D:"
            state: present
            type: string
            data: '\??\C:'