From 533656694eb39c40ef8fd4ec45d243f158db5c2d Mon Sep 17 00:00:00 2001 From: Jordan Borean Date: Thu, 30 Aug 2018 16:25:45 +1000 Subject: [PATCH] win_disk_image: return all mount paths in return value (#44799) --- .../fragments/win_disk_image-mount-paths.yaml | 4 ++++ .../rst/porting_guides/porting_guide_2.7.rst | 2 ++ lib/ansible/modules/windows/win_disk_image.ps1 | 14 ++++++++------ lib/ansible/modules/windows/win_disk_image.py | 9 +++++++-- 4 files changed, 21 insertions(+), 8 deletions(-) create mode 100644 changelogs/fragments/win_disk_image-mount-paths.yaml diff --git a/changelogs/fragments/win_disk_image-mount-paths.yaml b/changelogs/fragments/win_disk_image-mount-paths.yaml new file mode 100644 index 00000000000..3aa7b4ea687 --- /dev/null +++ b/changelogs/fragments/win_disk_image-mount-paths.yaml @@ -0,0 +1,4 @@ +minor_changes: +- win_disk_image - return a list of mount paths with the return value ``mount_paths``, this will always be a list and contain all mount points in an image +deprecated_features: +- win_disk_image - the return value ``mount_path`` is deprecated and will be removed in 2.11, this can be accessed through ``mount_paths[0]`` instead. diff --git a/docs/docsite/rst/porting_guides/porting_guide_2.7.rst b/docs/docsite/rst/porting_guides/porting_guide_2.7.rst index 05dde1a591b..f422bba52bc 100644 --- a/docs/docsite/rst/porting_guides/porting_guide_2.7.rst +++ b/docs/docsite/rst/porting_guides/porting_guide_2.7.rst @@ -201,6 +201,8 @@ Noteworthy module changes * The ``interface_name`` module option for ``na_ontap_net_vlan`` has been removed and should be removed from your playbooks +* The ``win_disk_image`` module has deprecated the return value ``mount_path``, use ``mount_paths[0]`` instead. This will + be removed in Ansible 2.11. Plugins ======= diff --git a/lib/ansible/modules/windows/win_disk_image.ps1 b/lib/ansible/modules/windows/win_disk_image.ps1 index b03cd1cb6f9..cbaada0a7d7 100644 --- a/lib/ansible/modules/windows/win_disk_image.ps1 +++ b/lib/ansible/modules/windows/win_disk_image.ps1 @@ -49,19 +49,21 @@ If($state -eq "present") { If($di.Attached) { # only try to get the mount_path if the disk is attached ( If($di.StorageType -eq 1) { # ISO, we can get the mountpoint directly from Get-Volume - $drive_letter = ($di | Get-Volume).DriveLetter + $drive_letters = ($di | Get-Volume).DriveLetter } ElseIf($di.StorageType -in @(2,3)) { # VHD/VHDX, need Get-Disk + Get-Partition to discover mountpoint - # FUTURE: support multi-partition VHDs - $drive_letter = ($di | Get-Disk | Get-Partition)[0].DriveLetter + $drive_letters = ($di | Get-Disk | Get-Partition).DriveLetter } + # remove any null entries (no drive letter) + $drive_letters = $drive_letters | Where-Object { $_ } - - If(-not $drive_letter) { + If(-not $drive_letters) { Fail-Json -message "Unable to retrieve drive letter from mounted image" } - $result.mount_path = $drive_letter + ":\" + # mount_path is deprecated and will be removed in 2.11, use mount_paths which contains all the partitions instead + $result.mount_path = $drive_letters[0] + ":\" + $result.mount_paths = @($drive_letters | ForEach-Object { "$($_):\" }) } } ElseIf($state -eq "absent") { diff --git a/lib/ansible/modules/windows/win_disk_image.py b/lib/ansible/modules/windows/win_disk_image.py index caa256822cf..2e942895cac 100644 --- a/lib/ansible/modules/windows/win_disk_image.py +++ b/lib/ansible/modules/windows/win_disk_image.py @@ -32,10 +32,15 @@ author: RETURN = r''' mount_path: - description: filesystem path where the target image is mounted + description: filesystem path where the target image is mounted, this has been deprecated in favour of C(mount_paths) returned: when C(state) is C(present) type: string sample: F:\ +mount_paths: + description: a list of filesystem paths mounted from the target image + returned: when C(state) is C(present) + type: list + sample: [ 'E:\', 'F:\' ] ''' EXAMPLES = r''' @@ -48,7 +53,7 @@ EXAMPLES = r''' - name: Run installer from mounted iso win_package: - path: '{{ disk_image_out.mount_path }}setup\setup.exe' + path: '{{ disk_image_out.mount_paths[0] }}setup\setup.exe' product_id: 35a4e767-0161-46b0-979f-e61f282fee21 state: present