From 84a651948166523ad43d80c532d5a6f880cb33bb Mon Sep 17 00:00:00 2001 From: rhydian76 Date: Tue, 5 Feb 2019 20:59:06 +0000 Subject: [PATCH] Windows facts for licensing information (#50079) * Windows facts for ansible_winlicense_edition, ansible_winlicense_channel, ansible_winlicense_status added * bugfix, replaced = with : * changed facts to ansible_os_license_* in win_product_facts.ps1 Shortened the short_description in win_product_facts.py removed errant - options: {} from win_product_facts.py * Code optimisations and changed return code to $null from NA when unknown license information returned from CIM SoftwareLicensingProduct class. * code optimisation --- .../modules/windows/win_product_facts.ps1 | 20 +++++++++++++++++++ .../modules/windows/win_product_facts.py | 6 ++++-- 2 files changed, 24 insertions(+), 2 deletions(-) diff --git a/lib/ansible/modules/windows/win_product_facts.ps1 b/lib/ansible/modules/windows/win_product_facts.ps1 index 6563bd92a00..873077cabf2 100644 --- a/lib/ansible/modules/windows/win_product_facts.ps1 +++ b/lib/ansible/modules/windows/win_product_facts.ps1 @@ -57,9 +57,29 @@ if (-not $product_key) { } } +# Retrieve license information +$license_info = Get-CimInstance SoftwareLicensingProduct | Where-Object PartialProductKey + +$winlicense_status = switch ($license_info.LicenseStatus) { + 0 { "Unlicensed" } + 1 { "Licensed" } + 2 { "OOBGrace" } + 3 { "OOTGrace" } + 4 { "NonGenuineGrace" } + 5 { "Notification" } + 6 { "ExtendedGrace" } + default { $null } +} + +$winlicense_edition = $license_info.Name +$winlicense_channel = $license_info.ProductKeyChannel + $module.Result.ansible_facts = @{ ansible_os_product_id = (Get-CimInstance Win32_OperatingSystem).SerialNumber ansible_os_product_key = $product_key + ansible_os_license_edition = $winlicense_edition + ansible_os_license_channel = $winlicense_channel + ansible_os_license_status = $winlicense_status } $module.ExitJson() diff --git a/lib/ansible/modules/windows/win_product_facts.py b/lib/ansible/modules/windows/win_product_facts.py index a54a8519f6d..c72d4c542f6 100644 --- a/lib/ansible/modules/windows/win_product_facts.py +++ b/lib/ansible/modules/windows/win_product_facts.py @@ -11,11 +11,10 @@ ANSIBLE_METADATA = {'metadata_version': '1.1', DOCUMENTATION = r''' --- module: win_product_facts -short_description: Provides Windows product information (product id, product key) +short_description: Provides Windows product and license information description: - Provides Windows product information. version_added: '2.5' -options: {} author: - Dag Wieers (@dagwieers) ''' @@ -33,4 +32,7 @@ ansible_facts: sample: ansible_os_product_id: 00326-10000-00000-AA698 ansible_os_product_key: T49TD-6VFBW-VV7HY-B2PXY-MY47H + ansible_os_license_edition: Windows(R) ServerStandard edition + ansible_os_license_channel: Volume:MAK + ansible_os_license_status: Licensed '''