From 2dd56eb15c1769794af6f2dcf1b9480d62675cc9 Mon Sep 17 00:00:00 2001 From: Dag Wieers Date: Sun, 11 Nov 2018 22:03:15 +0100 Subject: [PATCH] win_product_facts: Rewrite using AnsibleModule (#48382) --- .../modules/windows/win_product_facts.ps1 | 26 +++++++++---------- 1 file changed, 13 insertions(+), 13 deletions(-) diff --git a/lib/ansible/modules/windows/win_product_facts.ps1 b/lib/ansible/modules/windows/win_product_facts.ps1 index 78bc4db762..cda25826d3 100644 --- a/lib/ansible/modules/windows/win_product_facts.ps1 +++ b/lib/ansible/modules/windows/win_product_facts.ps1 @@ -3,20 +3,17 @@ # Copyright: (c) 2017, Dag Wieers (dagwieers) # GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt) -#Requires -Module Ansible.ModuleUtils.Legacy +#AnsibleRequires -CSharpUtil Ansible.Basic -$ErrorActionPreference = "Stop" - -# This module does not use any module parameters, this avoids pslint complaining -#$params = Parse-Args -arguments $args -supports_check_mode $true - -$result = @{ - changed = $false - ansible_facts = @{ - ansible_os_product_id = (Get-CimInstance Win32_OperatingSystem).SerialNumber - } +$spec = @{ + options = @{} + supports_check_mode = $true } +$module = [Ansible.Basic.AnsibleModule]::Create($args, $spec) + +$module.Result.changed = $false + # First try to find the product key from ACPI try { $product_key = (Get-CimInstance -Class SoftwareLicensingService).OA3xOriginalProductKey @@ -62,6 +59,9 @@ if (-not $product_key) { } } -$result.ansible_facts.ansible_os_product_key = $product_key +$module.Result.ansible_facts = @{ + ansible_os_product_id = (Get-CimInstance Win32_OperatingSystem).SerialNumber + ansible_os_product_key = $product_key +} -Exit-Json -obj $result +$module.ExitJson()