ansible-collections / community.windows

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

The win_disk_facts doesn't return dynamic disks #30

Open jborean93 opened 4 years ago

jborean93 commented 4 years ago

From @it-praktyk on Jan 17, 2019 16:52

SUMMARY

The module returns - as the ansible facts - only information about the first physical drive.

ISSUE TYPE
COMPONENT NAME

win_disk_facts

ANSIBLE VERSION
ansible 2.8.0.dev0
  config file = /etc/ansible/ansible.cfg
  configured module search path = [u'/home/<user_name>/.ansible/plugins/modules', u'/usr/share/ansible/plugins/modules']
  ansible python module location = /home/<folder_path>/ansible/lib/ansible
  executable location = /home/<folder_path>/ansible/bin/ansible
  python version = 2.7.15 (default, Oct 15 2018, 15:26:09) [GCC 8.2.1 20180801 (Red Hat 8.2.1-2)]
CONFIGURATION
ANSIBLE_NOCOWS(/etc/ansible/ansible.cfg) = True
OS / ENVIRONMENT

I tested that using the Vagrant image of Windows Server 2012 R2 jborean93/WindowsServer2012R2 v.0.5 with the additional disk added.

PS C:\Windows\system32> Get-PhysicalDisk

FriendlyName        CanPool             OperationalStatus   HealthStatus        Usage                              Size
------------        -------             -----------------   ------------        -----                              ----
PhysicalDisk0       False               OK                  Healthy             Auto-Select                    39.06 GB
PhysicalDisk1       False               OK                  Healthy             Auto-Select                       50 GB
STEPS TO REPRODUCE
ansible-test windows-integration win_disk_facts -vvv
EXPECTED RESULTS

ansible facts will contain information about all physical disks.

ACTUAL RESULTS

Only the first disk is included in the module output.

TASK [win_disk_facts : get disk facts on the target] **************************************************************************************************************************************************************
task path: /home/wojtek/Scripts/ansible/test/integration/targets/win_disk_facts/tasks/tests.yml:1
Using module file /home/wojtek/Scripts/ansible/lib/ansible/modules/windows/win_disk_facts.ps1
<127.0.0.1> ESTABLISH WINRM CONNECTION FOR USER: vagrant on PORT 2202 TO 127.0.0.1
EXEC (via pipeline wrapper)
ok: [local] => {
    "ansible_facts": {
        "ansible_disks": [
            {
                "bootable": true, 
                "bus_type": "ATA", 
                "clustered": false, 
                "firmware_version": "1.0", 
                "friendly_name": "VBOX HARDDISK ATA Device", 
                "guid": null, 
                "location": "PCIROOT(0)#PCI(0101)#ATA(C00T00L00)", 
                "manufacturer": null, 
                "model": "VBOX HARDDISK", 
                "number": 0, 
                "operational_status": "Online", 
                "partition_count": 2, 
                "partition_style": "MBR", 
                "partitions": [
                    {
                        "access_paths": [
                            "\\\\?\\Volume{db04a125-1a6a-11e9-80bf-806e6f6e6963}\\"
                        ], 
                        "active": true, 
                        "drive_letter": null, 
                        "guid": null, 
                        "hidden": false, 
                        "mbr_type": 7, 
                        "number": 1, 
                        "offset": 1048576, 
                        "shadow_copy": false, 
                        "size": 367001600, 
                        "transition_state": 1, 
                        "type": "IFS", 
                        "volumes": [
                            {
                                "allocation_unit_size": 4096, 
                                "drive_type": "Fixed", 
                                "health_status": "Healthy", 
                                "label": "boot", 
                                "object_id": "\\\\?\\Volume{db04a125-1a6a-11e9-80bf-806e6f6e6963}\\", 
                                "path": "\\\\?\\Volume{db04a125-1a6a-11e9-80bf-806e6f6e6963}\\", 
                                "size": 366997504, 
                                "size_remaining": 92086272, 
                                "type": "NTFS"
                            }
                        ]
                    }, 
                    {
                        "access_paths": [
                            "C:\\", 
                            "\\\\?\\Volume{db04a126-1a6a-11e9-80bf-806e6f6e6963}\\"
                        ], 
                        "active": false, 
                        "drive_letter": "C", 
                        "guid": null, 
                        "hidden": false, 
                        "mbr_type": 7, 
                        "number": 2, 
                        "offset": 368050176, 
                        "shadow_copy": false, 
                        "size": 41573941248, 
                        "transition_state": 1, 
                        "type": "IFS", 
                        "volumes": [
                            {
                                "allocation_unit_size": 4096, 
                                "drive_type": "Fixed", 
                                "health_status": "Healthy", 
                                "label": "Windows 2012r2", 
                                "object_id": "\\\\?\\Volume{db04a126-1a6a-11e9-80bf-806e6f6e6963}\\", 
                                "path": "\\\\?\\Volume{db04a126-1a6a-11e9-80bf-806e6f6e6963}\\", 
                                "size": 41573937152, 
                                "size_remaining": 31882354688, 
                                "type": "NTFS"
                            }
                        ]
                    }
                ], 
                "path": "\\\\?\\ide#diskvbox_harddisk___________________________1.0_____#5&3a5410d6&0&0.0.0#{53f56307-b6bf-11d0-94f2-00a0c91efb8b}", 
                "physical_disk": {
                    "allocated_size": 41943040000, 
                    "bus_type": "ATA", 
                    "can_pool": false, 
                    "cannot_pool_reason": "Insufficient Capacity", 
                    "device_id": "0", 
                    "firmware_version": "1.0", 
                    "friendly_name": "PhysicalDisk0", 
                    "health_status": "Healthy", 
                    "indication_enabled": null, 
                    "manufacturer": null, 
                    "media_type": "UnSpecified", 
                    "model": "VBOX HARDDISK", 
                    "object_id": "{1}\\\\WIN-CHMBD0MFEA4\\root/Microsoft/Windows/Storage/Providers_v2\\SPACES_PhysicalDisk.ObjectId=\"{db04a11f-1a6a-11e9-80bf-806e6f6e6963}:PD:{587e58d4-1a6c-11e9-80c2-806e6f6e6963}\"", 
                    "operational_status": "OK", 
                    "partial": true, 
                    "physical_location": null, 
                    "serial_number": "VB69f5b5da-74dc9a2f", 
                    "size": 41943040000, 
                    "spindle_speed": 4294967295, 
                    "supported_usages": {
                        "Count": 5, 
                        "value": [
                            "Auto-Select", 
                            "Manual-Select", 
                            "Hot Spare", 
                            "Retired", 
                            "Journal"
                        ]
                    }, 
                    "unique_id": "IDE\\DiskVBOX_HARDDISK___________________________1.0_____\\5&3a5410d6&0&0.0.0:WIN-CHMBD0MFEA4", 
                    "usage_type": "Auto-Select"
                }, 
                "read_only": false, 
                "sector_size": 512, 
                "serial_number": "VB69f5b5da-74dc9a2f", 
                "size": 41943040000, 
                "system_disk": true, 
                "unique_id": "IDE\\DISKVBOX_HARDDISK___________________________1.0_____\\5&3A5410D6&0&0.0.0:WIN-CHMBD0MFEA4"
            }
        ]
    }, 
    "changed": false
}

Copied from original issue: ansible/ansible#51032

jborean93 commented 4 years ago

From @marqelme on Jan 17, 2019 19:49

@it-praktyk It is working in my environment. Is it possible that the two physical disks have the same device ID? Then this would be the problem, because the script compares the Device ID of the physical disks with the disk numbers of Get-Disk:

foreach ($disk in $disks) { $disk_info = @{} $pdisk = Get-PhysicalDisk -ErrorAction SilentlyContinue | Where-Object { $_.DeviceId -eq $disk.Number } ... }

Example, physical Device ID and Disks number are the same:

unbenannt

jborean93 commented 4 years ago

From @it-praktyk on Jan 17, 2019 20:03

PS C:\Windows\system32> Get-PhysicalDisk | fl

ObjectId                         : {1}\\WIN-CHMBD0MFEA4\root/Microsoft/Windows/Storage/Providers_v2\SPACES_PhysicalDisk
                                   .ObjectId="{db04a11f-1a6a-11e9-80bf-806e6f6e6963}:PD:{44984255-1a91-11e9-80c3-806e6f
                                   6e6963}"
PassThroughClass                 :
PassThroughIds                   :
PassThroughNamespace             :
PassThroughServer                :
UniqueId                         : IDE\DiskVBOX_HARDDISK___________________________1.0_____\5&3a5410d6&0&0.0.0:WIN-CHMB
                                   D0MFEA4
AllocatedSize                    : 41943040000
BusType                          : ATA
CannotPoolReason                 : Insufficient Capacity
CanPool                          : False
Description                      :
DeviceId                         : 0
EnclosureNumber                  :
FirmwareVersion                  : 1.0
FriendlyName                     : PhysicalDisk0
HealthStatus                     : Healthy
IsIndicationEnabled              :
IsPartial                        : True
LogicalSectorSize                : 512
Manufacturer                     :
MediaType                        : UnSpecified
Model                            : VBOX HARDDISK
OperationalStatus                : OK
OtherCannotPoolReasonDescription :
PartNumber                       :
PhysicalLocation                 :
PhysicalSectorSize               : 512
SerialNumber                     : VB69f5b5da-74dc9a2f
Size                             : 41943040000
SlotNumber                       :
SoftwareVersion                  :
SpindleSpeed                     : 4294967295
SupportedUsages                  : {Auto-Select, Manual-Select, Hot Spare, Retired...}
Usage                            : Auto-Select
PSComputerName                   :

ObjectId                         : {1}\\WIN-CHMBD0MFEA4\root/Microsoft/Windows/Storage/Providers_v2\SPACES_PhysicalDisk
                                   .ObjectId="{db04a11f-1a6a-11e9-80bf-806e6f6e6963}:PD:{44984256-1a91-11e9-80c3-806e6f
                                   6e6963}"
PassThroughClass                 :
PassThroughIds                   :
PassThroughNamespace             :
PassThroughServer                :
UniqueId                         : IDE\DiskVBOX_HARDDISK___________________________1.0_____\5&3a5410d6&0&0.1.0:WIN-CHMB
                                   D0MFEA4
AllocatedSize                    : 53687091200
BusType                          : ATA
CannotPoolReason                 : Insufficient Capacity
CanPool                          : False
Description                      :
DeviceId                         : 1
EnclosureNumber                  :
FirmwareVersion                  : 1.0
FriendlyName                     : PhysicalDisk1
HealthStatus                     : Healthy
IsIndicationEnabled              :
IsPartial                        : True
LogicalSectorSize                : 512
Manufacturer                     :
MediaType                        : UnSpecified
Model                            : VBOX HARDDISK
OperationalStatus                : OK
OtherCannotPoolReasonDescription :
PartNumber                       :
PhysicalLocation                 :
PhysicalSectorSize               : 512
SerialNumber                     : VB4b8a8cc9-b8992ce5
Size                             : 53687091200
SlotNumber                       :
SoftwareVersion                  :
SpindleSpeed                     : 4294967295
SupportedUsages                  : {Auto-Select, Manual-Select, Hot Spare, Retired...}
Usage                            : Auto-Select
PSComputerName                   :
PS C:\Windows\system32> Get-Disk | fl

UniqueId           : IDE\DISKVBOX_HARDDISK___________________________1.0_____\5&3A5410D6&0&0.0.0:WIN-CHMBD0MFEA4
Number             : 0
Path               : \\?\ide#diskvbox_harddisk___________________________1.0_____#5&3a5410d6&0&0.0.0#{53f56307-b6bf-11d
                     0-94f2-00a0c91efb8b}
Manufacturer       :
Model              : VBOX HARDDISK
SerialNumber       : VB69f5b5da-74dc9a2f
Size               : 39.06 GB
AllocatedSize      : 41943040000
LogicalSectorSize  : 512
PhysicalSectorSize : 512
NumberOfPartitions : 2
PartitionStyle     : MBR
IsReadOnly         : False
IsSystem           : True
IsBoot             : True

The synopsis of the Get-Disk cmdlet: "Gets one or more disks visible to the operating system.". It probably an answer why the second physical disk is not returned - because it's not partitioned.

jborean93 commented 4 years ago

From @marqelme on Jan 17, 2019 20:18

Yes right, if Get-Disk does not see it, it will not appear in the facts.

jborean93 commented 4 years ago

From @it-praktyk on Jan 17, 2019 21:24

It can be about dynamic disks

Q: How do I use Windows PowerShell to manage my dynamic disks.

A: You don’t. The dynamic disks that have been part of Windows since Windows 2000 are being deprecated. While still available in the product, Microsoft has provided no Windows PowerShell cmdlets to manage dynamic disks. Source: Tip of the Day: Dynamic Disks and Windows PowerShell

jborean93 commented 4 years ago

From @it-praktyk on Jan 17, 2019 22:06

The resolution will be a usage of the command like below instead of Get-Disk. Next, compare the results with the results of Get-Disk to identify missed (they are dynamic).

PS C:\Windows\system32> Get-CimInstance -class Win32_diskdrive | fl -Property *

ConfigManagerErrorCode      : 0
LastErrorCode               :
NeedsCleaning               :
Status                      : OK
DeviceID                    : \\.\PHYSICALDRIVE1
StatusInfo                  :
Partitions                  : 0
BytesPerSector              : 512
ConfigManagerUserConfig     : False
DefaultBlockSize            :
Index                       : 1
InstallDate                 :
InterfaceType               : IDE
MaxBlockSize                :
MaxMediaSize                :
MinBlockSize                :
NumberOfMediaSupported      :
SectorsPerTrack             : 63
Size                        : 53686402560
TotalCylinders              : 6527
TotalHeads                  : 255
TotalSectors                : 104856255
TotalTracks                 : 1664385
TracksPerCylinder           : 255
Caption                     : VBOX HARDDISK ATA Device
Description                 : Disk drive
Name                        : \\.\PHYSICALDRIVE1
Availability                :
CreationClassName           : Win32_DiskDrive
ErrorCleared                :
ErrorDescription            :
PNPDeviceID                 : IDE\DISKVBOX_HARDDISK___________________________1.0_____\5&3A5410D6&0&0.1.0
PowerManagementCapabilities :
PowerManagementSupported    :
SystemCreationClassName     : Win32_ComputerSystem
SystemName                  : WIN-CHMBD0MFEA4
Capabilities                : {3, 4, 10}
CapabilityDescriptions      : {Random Access, Supports Writing, SMART Notification}
CompressionMethod           :
ErrorMethodology            :
FirmwareRevision            : 1.0
Manufacturer                : (Standard disk drives)
MediaLoaded                 : True
MediaType                   : Fixed hard disk media
Model                       : VBOX HARDDISK ATA Device
SCSIBus                     : 0
SCSILogicalUnit             : 0
SCSIPort                    : 0
SCSITargetId                : 1
SerialNumber                : VB4b8a8cc9-b8992ce5
Signature                   :
PSComputerName              :
CimClass                    : root/cimv2:Win32_DiskDrive
CimInstanceProperties       : {Caption, Description, InstallDate, Name...}
CimSystemProperties         : Microsoft.Management.Infrastructure.CimSystemProperties

ConfigManagerErrorCode      : 0
LastErrorCode               :
NeedsCleaning               :
Status                      : OK
DeviceID                    : \\.\PHYSICALDRIVE0
StatusInfo                  :
Partitions                  : 2
BytesPerSector              : 512
ConfigManagerUserConfig     : False
DefaultBlockSize            :
Index                       : 0
InstallDate                 :
InterfaceType               : IDE
MaxBlockSize                :
MaxMediaSize                :
MinBlockSize                :
NumberOfMediaSupported      :
SectorsPerTrack             : 63
Size                        : 41940702720
TotalCylinders              : 5099
TotalHeads                  : 255
TotalSectors                : 81915435
TotalTracks                 : 1300245
TracksPerCylinder           : 255
Caption                     : VBOX HARDDISK ATA Device
Description                 : Disk drive
Name                        : \\.\PHYSICALDRIVE0
Availability                :
CreationClassName           : Win32_DiskDrive
ErrorCleared                :
ErrorDescription            :
PNPDeviceID                 : IDE\DISKVBOX_HARDDISK___________________________1.0_____\5&3A5410D6&0&0.0.0
PowerManagementCapabilities :
PowerManagementSupported    :
SystemCreationClassName     : Win32_ComputerSystem
SystemName                  : WIN-CHMBD0MFEA4
Capabilities                : {3, 4, 10}
CapabilityDescriptions      : {Random Access, Supports Writing, SMART Notification}
CompressionMethod           :
ErrorMethodology            :
FirmwareRevision            : 1.0
Manufacturer                : (Standard disk drives)
MediaLoaded                 : True
MediaType                   : Fixed hard disk media
Model                       : VBOX HARDDISK ATA Device
SCSIBus                     : 0
SCSILogicalUnit             : 0
SCSIPort                    : 0
SCSITargetId                : 0
SerialNumber                : VB69f5b5da-74dc9a2f
Signature                   : 1315726724
PSComputerName              :
CimClass                    : root/cimv2:Win32_DiskDrive
CimInstanceProperties       : {Caption, Description, InstallDate, Name...}
CimSystemProperties         : Microsoft.Management.Infrastructure.CimSystemProperties
jborean93 commented 4 years ago

From @marqelme on Jan 17, 2019 22:24

I don‘t know in this should be added if it is deprecated. Let‘s See what the ihrer guys think about it.

Outlook für iOShttps://aka.ms/o0ukef beziehen


Von: Wojciech Sciesinski notifications@github.com Gesendet: Donnerstag, Januar 17, 2019 11:08 PM An: ansible/ansible Cc: Marc Tschapek; Mention Betreff: Re: [ansible/ansible] The win_disk_facts doesn't return dynamic disks (#51032)

The resolution will be a usage of the command like below instead of Get-Disk. Next, compare the results with the results of Get-Disk to identify missed (they are dynamic).

PS C:\Windows\system32> Get-CimInstance -class Win32_diskdrive | fl -Property *

ConfigManagerErrorCode : 0 LastErrorCode : NeedsCleaning : Status : OK DeviceID : \.\PHYSICALDRIVE1 StatusInfo : Partitions : 0 BytesPerSector : 512 ConfigManagerUserConfig : False DefaultBlockSize : Index : 1 InstallDate : InterfaceType : IDE MaxBlockSize : MaxMediaSize : MinBlockSize : NumberOfMediaSupported : SectorsPerTrack : 63 Size : 53686402560 TotalCylinders : 6527 TotalHeads : 255 TotalSectors : 104856255 TotalTracks : 1664385 TracksPerCylinder : 255 Caption : VBOX HARDDISK ATA Device Description : Disk drive Name : \.\PHYSICALDRIVE1 Availability : CreationClassName : Win32_DiskDrive ErrorCleared : ErrorDescription : PNPDeviceID : IDE\DISKVBOX_HARDDISK___1.0_\5&3A5410D6&0&0.1.0 PowerManagementCapabilities : PowerManagementSupported : SystemCreationClassName : Win32_ComputerSystem SystemName : WIN-CHMBD0MFEA4 Capabilities : {3, 4, 10} CapabilityDescriptions : {Random Access, Supports Writing, SMART Notification} CompressionMethod : ErrorMethodology : FirmwareRevision : 1.0 Manufacturer : (Standard disk drives) MediaLoaded : True MediaType : Fixed hard disk media Model : VBOX HARDDISK ATA Device SCSIBus : 0 SCSILogicalUnit : 0 SCSIPort : 0 SCSITargetId : 1 SerialNumber : VB4b8a8cc9-b8992ce5 Signature : PSComputerName : CimClass : root/cimv2:Win32_DiskDrive CimInstanceProperties : {Caption, Description, InstallDate, Name...} CimSystemProperties : Microsoft.Management.Infrastructure.CimSystemProperties

ConfigManagerErrorCode : 0 LastErrorCode : NeedsCleaning : Status : OK DeviceID : \.\PHYSICALDRIVE0 StatusInfo : Partitions : 2 BytesPerSector : 512 ConfigManagerUserConfig : False DefaultBlockSize : Index : 0 InstallDate : InterfaceType : IDE MaxBlockSize : MaxMediaSize : MinBlockSize : NumberOfMediaSupported : SectorsPerTrack : 63 Size : 41940702720 TotalCylinders : 5099 TotalHeads : 255 TotalSectors : 81915435 TotalTracks : 1300245 TracksPerCylinder : 255 Caption : VBOX HARDDISK ATA Device Description : Disk drive Name : \.\PHYSICALDRIVE0 Availability : CreationClassName : Win32_DiskDrive ErrorCleared : ErrorDescription : PNPDeviceID : IDE\DISKVBOX_HARDDISK___1.0_\5&3A5410D6&0&0.0.0 PowerManagementCapabilities : PowerManagementSupported : SystemCreationClassName : Win32_ComputerSystem SystemName : WIN-CHMBD0MFEA4 Capabilities : {3, 4, 10} CapabilityDescriptions : {Random Access, Supports Writing, SMART Notification} CompressionMethod : ErrorMethodology : FirmwareRevision : 1.0 Manufacturer : (Standard disk drives) MediaLoaded : True MediaType : Fixed hard disk media Model : VBOX HARDDISK ATA Device SCSIBus : 0 SCSILogicalUnit : 0 SCSIPort : 0 SCSITargetId : 0 SerialNumber : VB69f5b5da-74dc9a2f Signature : 1315726724 PSComputerName : CimClass : root/cimv2:Win32_DiskDrive CimInstanceProperties : {Caption, Description, InstallDate, Name...} CimSystemProperties : Microsoft.Management.Infrastructure.CimSystemProperties

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHubhttps://github.com/ansible/ansible/issues/51032#issuecomment-455349724, or mute the threadhttps://github.com/notifications/unsubscribe-auth/AcZinKTOwun6Z6w-w-fwTB1ha5LpbG4Dks5vEPRBgaJpZM4aGT09.

jborean93 commented 4 years ago

From @it-praktyk on Jan 17, 2019 22:29

IMHO, they should be returned by win_disk_facts but can't be managed by other windisk* modules (in the future).

BTW, that has to be tested with storage spaces too.

jborean93 commented 4 years ago

From @it-praktyk on Jan 18, 2019 15:28

The module doesn't provide facts about disk those are storage pools members as well.

jborean93 commented 4 years ago

From @nitzmahone on Jan 22, 2019 20:07

+1 from Working Group discussion