Add productType property as an ansible fact (#41139)

* Add productType property as an ansible fact

Suggest to add productType property from win32_operatingsystem CIM instance to differentiate between versions and add new fact.

* update code to display human-readable string

Commit added in response to nizmahone's suggestion to add humane-readable strings to the display. uses switch statement to evaluate and update $ansible_facts hash table with proper information

* remove string conversion, modify switch default

Adjusts line 202 to remove .String() conversion from uInt32.
Adjusts switch test values to integers
Uses switch default clause to handle null values

* formatting

fixed formatting issues, moved product_type into variable.
adjust ansible_fact hash table key to be consistent with the rest of the code.

* Moved product type within distribution
This commit is contained in:
Steve Jennings 2018-06-25 22:03:50 -04:00 committed by Jordan Borean
parent abfcc35e6f
commit 57ea4cafff

View file

@ -192,12 +192,20 @@ if($gather_subset.Contains('date_time')) {
if($gather_subset.Contains('distribution')) { if($gather_subset.Contains('distribution')) {
$win32_os = Get-LazyCimInstance Win32_OperatingSystem $win32_os = Get-LazyCimInstance Win32_OperatingSystem
$product_type = switch($win32_os.ProductType) {
1 { "workstation" }
2 { "domain_controller" }
3 { "server" }
default { "unknown" }
}
$ansible_facts += @{ $ansible_facts += @{
ansible_distribution = $win32_os.Caption ansible_distribution = $win32_os.Caption
ansible_distribution_version = $osversion.Version.ToString() ansible_distribution_version = $osversion.Version.ToString()
ansible_distribution_major_version = $osversion.Version.Major.ToString() ansible_distribution_major_version = $osversion.Version.Major.ToString()
ansible_os_family = "Windows" ansible_os_family = "Windows"
ansible_os_name = ($win32_os.Name.Split('|')[0]).Trim() ansible_os_name = ($win32_os.Name.Split('|')[0]).Trim()
ansible_os_product_type = $product_type
} }
} }