On a physical server with ejectable disks the win_disk_facts fails with error:
Cannot validate argument on parameter 'PhysicalDisk'
The full traceback is:
Cannot validate argument on parameter 'PhysicalDisk'. The argument is null. Provide a valid value for the argument, and then try running the command again.\r
At line:89 char:52\r
+ $vdisk = Get-VirtualDisk -PhysicalDisk $pdisk -ErrorActio ...\r
+ ~~~~~~\r
+ CategoryInfo : InvalidData: (:) [Get-VirtualDisk], ParentContainsErrorRecordException\r
+ FullyQualifiedErrorId : ParameterArgumentValidationError,Get-VirtualDisk\r
\r
ScriptStackTrace:\r
at <ScriptBlock>, <No file>: line 89\r
fatal: [<hostname obscured>]: FAILED! => {
"changed": false,
"msg": "Unhandled exception while executing module: Cannot validate argument on parameter 'PhysicalDisk'. The argument is null. Provide a valid value for the argument, and then try running the command again."
}
ISSUE TYPE
Bug Report
COMPONENT NAME
win_disk_facts
ANSIBLE VERSION
2.10
COLLECTION VERSION
1.11.1
CONFIGURATION
It is a HP synergy blade server.
Somehow an extra (ejectable) harddisk is visible.
Note that Get-Disk shows this disk, Get-PhysicalDisk does not
Get-Disk
Number Friendly Name Serial Number HealthStatus OperationalStatus Total Size Partition Style
------ ------------- ------------- ------------ ----------------- ---------- ---------------
0 HPE LOGICAL VOLUME PEYJE0BRHCU09J Healthy Online 120 GB GPT
1 HPE LOGICAL VOLUME PEYJE0BRHCU09J Healthy Online 50 GB GPT
2 HPE LOGICAL VOLUME PEYJE0BRHCU09J Healthy Online 75 GB GPT
3 Generic- SD/MMC CRW 2012062914345300 Healthy No Media 0 B RAW
This then is also the cause of the bug:
There is an outer loop on output of 'Get-Disk' which loops over disks 0-3 and tries to capture physicaldisk information using Get-PhysicalDisk, but disk #3 does not exist.
So the last iteration in the loop causes the variable to be undefined.
OS / ENVIRONMENT
Windows Server 2019 on hardware
STEPS TO REPRODUCE
You'll need a machine / hardware with a removable harddisk that gives above PowerShell output. (1 disk more in output than in output from get-physicaldisk)
Bug:
in line 50 - 274 the outer loop loops over all disks
in line 54 the variable $pdisk is loaded
lines 58-87 is a conditional block that only runs if $pdisk is defined
Lines 88-126 another block of code, using the $pdisk variable but it is not defined in (our) last iteration causing the error.
To SOLVE the issue (tested):
Move the code in lines 88-126 within the outer 'If' loop that starts in line 58
This causes the code for virtual disk to only be ran if $pdisk is defined.
SUMMARY
On a physical server with ejectable disks the win_disk_facts fails with error: Cannot validate argument on parameter 'PhysicalDisk'
ISSUE TYPE
COMPONENT NAME
win_disk_facts
ANSIBLE VERSION
COLLECTION VERSION
CONFIGURATION
It is a HP synergy blade server. Somehow an extra (ejectable) harddisk is visible. Note that Get-Disk shows this disk, Get-PhysicalDisk does not
This then is also the cause of the bug: There is an outer loop on output of 'Get-Disk' which loops over disks 0-3 and tries to capture physicaldisk information using Get-PhysicalDisk, but disk #3 does not exist. So the last iteration in the loop causes the variable to be undefined.
OS / ENVIRONMENT
Windows Server 2019 on hardware
STEPS TO REPRODUCE
You'll need a machine / hardware with a removable harddisk that gives above PowerShell output. (1 disk more in output than in output from get-physicaldisk)
Bug:
To SOLVE the issue (tested):
EXPECTED RESULTS
Normal disk facts
ACTUAL RESULTS
Error as described above.