ansible-collections / community.windows

Windows community collection for Ansible
https://galaxy.ansible.com/community/windows
GNU General Public License v3.0
198 stars 153 forks source link

Support access_path as alternative to drive_letter in `win_partition` #490

Open jantari opened 1 year ago

jantari commented 1 year ago
SUMMARY

Support NTFS Access path mounting for partitions as an alternative to DOS-style drive letters. For example hrough Add-PartitionAccessPath.

ISSUE TYPE
COMPONENT NAME

win_partition

ADDITIONAL INFORMATION

Currently community.windows.win_partition can only assign DOS-style drive letters to partitions.

However, drive letters are difficult and inconsistent to automate - depending on how many CDROM drives a VM has, an arbitrary number of letters may be taken and they are difficult to shuffle around.

Replacing an older server with a new one that has slightly different disk / optical drive configuration can completely foil any attempts to reuse drive letter assignments from the old machine etc., it's just a hassle and I really don't want to use drive letters for anything ever.

For example the task:

    - name: Create partition
      community.windows.win_partition:
        disk_number: 1
        partition_size: -1 # maximum available size
        drive_letter: E

would become:

    - name: Create partition
      community.windows.win_partition:
        disk_number: 1
        partition_size: -1 # maximum available size
        access_path: '{{ ansible_env.SystemDrive }}\WhateverMountPoint'

An alternative that works today, and I've used in the past, is to do it through DSC - but native support directly in win_partition would be far nicer:

    - name: Make sure mount-directory exists
      ansible.windows.win_file:
        path: '{{ ansible_env.SystemDrive }}\WhateverMountPoint'
        state: directory

    - name: Install StorageDsc DSC module
      community.windows.win_psmodule:
        name: StorageDsc
        state: present

    - name: Create and format partition
      ansible.windows.win_dsc:
        resource_name: DiskAccessPath
        DiskIdType: Number
        DiskId: 1
        AccessPath: '{{ ansible_env.SystemDrive }}\WhateverMountPoint'
        FSFormat: NTFS

Thanks!!