Ansible to SUBST a drive machine-wide

320 views Asked by At

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?

2

There are 2 answers

1
Bijou Trouvaille On BEST ANSWER

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:'
1
JPBlanc On

I don't know why you want to do that, but you can try to use workstation service :

Net use d: \\localhost\c$

One problem you may encouter is that the command has to be run by the same user who use it, for example, if you run it in an elevated administrator shell, you won't see it in a simple user shell.