From 57ea4cafff476197f53583345df4b63bd1a17a73 Mon Sep 17 00:00:00 2001 From: Steve Jennings Date: Mon, 25 Jun 2018 22:03:50 -0400 Subject: [PATCH] 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 --- lib/ansible/modules/windows/setup.ps1 | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/lib/ansible/modules/windows/setup.ps1 b/lib/ansible/modules/windows/setup.ps1 index 6fc9f273ed..36e70b0bd2 100644 --- a/lib/ansible/modules/windows/setup.ps1 +++ b/lib/ansible/modules/windows/setup.ps1 @@ -192,12 +192,20 @@ if($gather_subset.Contains('date_time')) { if($gather_subset.Contains('distribution')) { $win32_os = Get-LazyCimInstance Win32_OperatingSystem + $product_type = switch($win32_os.ProductType) { + 1 { "workstation" } + 2 { "domain_controller" } + 3 { "server" } + default { "unknown" } + } + $ansible_facts += @{ ansible_distribution = $win32_os.Caption ansible_distribution_version = $osversion.Version.ToString() ansible_distribution_major_version = $osversion.Version.Major.ToString() ansible_os_family = "Windows" ansible_os_name = ($win32_os.Name.Split('|')[0]).Trim() + ansible_os_product_type = $product_type } }