Repository: ansible/ansible
Pull request: win_disk_facts: Prefix facts with ansible_ and use raw values
##### SUMMARY
This fixes #35325 
This fixes #35329 

##### ISSUE TYPE
 - Bugfix Pull Request

##### COMPONENT NAME
win_disk_facts

##### ANSIBLE VERSION
v2.5

Problem statement:
win_disk_facts: facts are not being ansible_ namespaced
##### ISSUE TYPE
 - Bug Report

##### COMPONENT NAME
win_disk_facts

##### ANSIBLE VERSION
v2.5

##### SUMMARY
So we established that facts need to be namespaced using a `ansible_` prefix. If not they may be conflicting/overriding user variables. Since this module is exposing its information as `disks` that's a problem, it ought to be `ansible_disks`.

win_disk_facts: Should expose raw values
##### ISSUE TYPE
 - Bug Report

##### COMPONENT NAME
win_disk_facts

##### ANSIBLE VERSION
v2.5

##### SUMMARY
Currently there's no way to get the disk size in a format you can manipulate. For instance, the disk ought to be a 240GB disk. However the value is returned as:
```yaml
                "size": "223.57088470459GiB", 
```
But since it is a string, we cannot convert to a float and recalculate in GB. Which we could be doing like this:
```yaml
  - name: Isolate disk
    set_fact:
      disk: '{{ ansible_facts.disks|selectattr("system_disk")|first }}'

  - name: Set disk size
    set_fact:
      disk_size: '{{ (disk.size|float*1024*1024/1000/1000)|round|int }}GB'
```

Hints from issue discussion:
Files identified in the description:
* [lib/ansible/modules/windows/win_disk_facts.ps1](https://github.com/ansible/ansible/blob/devel/lib/ansible/modules/windows/win_disk_facts.ps1)

If these files are inaccurate, please update the `component name` section of the description or use the `!component` bot command.

[click here for bot help](https://github.com/ansible/ansibullbot/blob/master/ISSUE_HELP.md)
<!--- boilerplate: components_banner --->
cc @jborean93 @jhawkesworth @marqelme @nitzmahone
[click here for bot help](https://github.com/ansible/ansibullbot/blob/master/ISSUE_HELP.md)
<!--- boilerplate: notify --->

Commit message: win_disk_facts: Prefix facts with ansible_

Patch to review:
diff --git a/lib/ansible/modules/windows/win_disk_facts.ps1 b/lib/ansible/modules/windows/win_disk_facts.ps1
index ac3f642769f7a1..67e877e6589b78 100644
--- a/lib/ansible/modules/windows/win_disk_facts.ps1
+++ b/lib/ansible/modules/windows/win_disk_facts.ps1
@@ -8,15 +8,6 @@
 $ErrorActionPreference = "Stop"
 Set-StrictMode -Version 2.0
 
-# Create a new result object
-$result = @{
-    changed = $false
-    ansible_facts = @{
-        total_disks = 0
-        disks = @()
-    }
-}
-
 # Functions 
 function Test-Admin {
         $CurrentUser = New-Object Security.Principal.WindowsPrincipal $([Security.Principal.WindowsIdentity]::GetCurrent())
@@ -27,9 +18,15 @@ function Test-Admin {
 
 # Check admin rights
 if (-not (Test-Admin)) {
-    $result.Remove("total_disks")
-    $result.Remove("disks")
-    Fail-Json -obj $result -message "Cmdlet was not started with elevated rights"
+    Fail-Json -message "Cmdlet was not started with elevated rights"
+}
+
+# Create a new result object
+$result = @{
+    changed = $false
+    ansible_facts = @{
+        ansible_disks = @()
+    }
 }
 
 # Search disks
@@ -39,7 +36,7 @@ try {
     Fail-Json -obj $result -message "Failed to search the disks on the target: $($_.Exception.Message)"
 }
 [int32]$diskcount = $disks | Measure-Object | Select-Object  -ExpandProperty Count
-$result.ansible_facts.total_disks = $diskcount
+#$result.ansible_facts.total_disks = $diskcount
 foreach ($disk in $disks) {
     $disk_info = @{}
     $pdisk = Get-PhysicalDisk -ErrorAction SilentlyContinue | Where-Object {
@@ -183,7 +180,7 @@ foreach ($disk in $disks) {
         $disk_info.partitions += $partition_info
         }
     }
-    $result.ansible_facts.disks += $disk_info
+    $result.ansible_facts.ansible_disks += $disk_info
 }
 
 # Return result
diff --git a/lib/ansible/modules/windows/win_disk_facts.py b/lib/ansible/modules/windows/win_disk_facts.py
index 957a74fbaaacf7..6ed0e6b68a536b 100644
--- a/lib/ansible/modules/windows/win_disk_facts.py
+++ b/lib/ansible/modules/windows/win_disk_facts.py
@@ -29,12 +29,14 @@
 EXAMPLES = r'''
 - name: get disk facts
   win_disk_facts:
+
 - name: output first disk size
   debug:
     var: ansible_facts.disks[0].size
 
 - name: get disk facts
   win_disk_facts:
+
 - name: output second disk serial number
   debug:
     var: ansible_facts.disks[0].serial_number
@@ -46,12 +48,7 @@
     returned: always
     type: complex
     contains:
-        total_disks:
-            description: Count of found disks on the target.
-            returned: if disks were found
-            type: int
-            sample: 3
-        disks:
+        ansible_disks:
             description: Detailed information about one particular disk.
             returned: if disks were found
             type: list


Code review comments:
diff_hunk: @@ -39,7 +36,7 @@ try {
     Fail-Json -obj $result -message "Failed to search the disks on the target: $($_.Exception.Message)"
 }
 [int32]$diskcount = $disks | Measure-Object | Select-Object  -ExpandProperty Count
-$result.ansible_facts.total_disks = $diskcount
+#$result.ansible_facts.total_disks = $diskcount
path: lib/ansible/modules/windows/win_disk_facts.ps1
text: @user1:
May as well just remove the line if you are not going to return it anymore.

@author:
That was the intention, thanks for catching this :-)