Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

win_product_facts: New module to get Windows product information #35206

Merged
merged 4 commits into from
Jan 23, 2018

Conversation

dagwieers
Copy link
Contributor

SUMMARY

This PR includes a new module that returns Windows product information, and includes product id and product key information.

ISSUE TYPE
  • New Module Pull Request
COMPONENT NAME

win_product_facts

ANSIBLE VERSION

v2.5

So this is actually a very nice way to get product key information from
systems collected centrally.

Especially with systems that have been upgraded from Windows 7 or
Windows 8 to Windows 10 may not have a valid Windows 10 product
license key printed anywhere, it was a digital license.

If you ever have to reinstall the system, you may recover the system
from the recovery partition, or the original media, but cannot upgrade
to Windows 10 for free. By collecting the product key, one can always
reinstall your free Windows upgrade.

My only question is, do we want this to be part of the default facts, as
it may be considered important information. Or should we make a special
**win_product_key_facts** ?
@dagwieers dagwieers added the windows Windows community label Jan 22, 2018
@dagwieers dagwieers added this to the 2.5.0 milestone Jan 22, 2018
@ansibot
Copy link
Contributor

ansibot commented Jan 22, 2018

@ansibot ansibot added affects_2.5 This issue/PR affects Ansible v2.5 community_review In order to be merged, this PR must follow the community review workflow. module This issue/PR relates to a module. new_module This PR includes a new module. new_plugin This PR includes a new plugin. support:community This issue/PR relates to code supported by the Ansible community. labels Jan 22, 2018
ansible_os_product_id = (Get-CimInstance Win32_OperatingSystem).SerialNumber
ansible_os_product_key = Get-ProductKey
}
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No Exit-Json

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed now.

#!powershell
# This file is part of Ansible

# Copyright: (c) 2017, Dag Wieers (dagwieers) <dag@wieers.com>
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's 2018 now :)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The code originated from 2017 ;-)

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just living the the past, gotta let it go :)

'''

EXAMPLES = r'''
- name: Set product id and product key
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

s/set/get/

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Right, depends from what perspective ;-)

Copy link
Member

@nitzmahone nitzmahone left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Overall LGTM, just maybe a little defensive coding around the lookup/parsing of the fallback and tiny doc typo

'''

EXAMPLES = r'''
- name: Set product id and product key
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

s/Set/Get

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Depends on your perspective ;-)


if (-not $product_key) {
# Else try to get it from the registry instead
$data = Get-ItemPropertyValue -Path "HKLM:\Software\Microsoft\Windows NT\CurrentVersion" -Name DigitalProductId
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What if it's not there or not in the format you're expecting?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The if-it's-not-there is now covered. If the format is not as I expect the resulting key will be corrupted. I wouldn't expect this to be the case though.


Function Get-ProductKey {
# First try to find the product key from ACPI
$product_key = (Get-CimInstance -Class SoftwareLicensingService).OA3xOriginalProductKey
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Probably also want a -ErrorAction Continue here in case the CIM class or property is not defined (eg, Server 2008)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

But then you cannot get to the OA3xOriginalProductKey property either. So should it be a try/catch instead ?

@dagwieers
Copy link
Contributor Author

So I think I covered everything, except a corrupted registry key. I don't know if that's to be expected.

@ansibot ansibot added test This PR relates to tests. needs_revision This PR fails CI tests or a maintainer has requested a review/revision of the PR. and removed community_review In order to be merged, this PR must follow the community review workflow. labels Jan 22, 2018
@jborean93 jborean93 merged commit 2a4b3ef into ansible:devel Jan 23, 2018
Lujeni pushed a commit to Lujeni/ansible that referenced this pull request Feb 1, 2018
…ible#35206)

* win_setup: Add Product ID and Product Key in facts

So this is actually a very nice way to get product key information from
systems collected centrally.

Especially with systems that have been upgraded from Windows 7 or
Windows 8 to Windows 10 may not have a valid Windows 10 product
license key printed anywhere, it was a digital license.

If you ever have to reinstall the system, you may recover the system
from the recovery partition, or the original media, but cannot upgrade
to Windows 10 for free. By collecting the product key, one can always
reinstall your free Windows upgrade.

My only question is, do we want this to be part of the default facts, as
it may be considered important information. Or should we make a special
**win_product_key_facts** ?

* Add ACPI product key support

* Add integration test

* Remove Get-ProductKey function, move inline
@ansible ansible locked and limited conversation to collaborators Apr 26, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
affects_2.5 This issue/PR affects Ansible v2.5 module This issue/PR relates to a module. needs_revision This PR fails CI tests or a maintainer has requested a review/revision of the PR. new_module This PR includes a new module. new_plugin This PR includes a new plugin. support:community This issue/PR relates to code supported by the Ansible community. test This PR relates to tests. windows Windows community
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants