Skip to content

Commit

Permalink
setup - Add ansible_os_install_date fact
Browse files Browse the repository at this point in the history
Adds the ansible_os_install_date fact that contains the OS installation
date as an ISO 8601 string value.
  • Loading branch information
jborean93 committed Oct 31, 2024
1 parent 402897e commit 824e8d5
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 1 deletion.
5 changes: 5 additions & 0 deletions changelogs/fragments/setup-install-date.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
minor_changes:
- >-
setup - Added ``ansible_os_install_date`` as the OS installation date in the ISO 8601 format
``yyyy-MM-ddTHH:mm:ssZ``. This date is represented in the UTC timezone -
https://github.com/ansible-collections/ansible.windows/issues/663
7 changes: 6 additions & 1 deletion plugins/modules/setup.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -652,7 +652,7 @@ $factMeta = @(

$osInfoParams = @{
LiteralPath = 'HKLM:\SOFTWARE\Microsoft\Windows NT\CurrentVersion'
Name = 'InstallationType'
Name = 'InstallationType', 'InstallTime'
ErrorAction = 'SilentlyContinue'
}
$osInfo = Get-ItemProperty @osInfoParams
Expand All @@ -664,6 +664,11 @@ $factMeta = @(
$ansibleFacts.ansible_os_name = $null
$ansibleFacts.ansible_os_product_type = $productType
$ansibleFacts.ansible_os_installation_type = $osInfo.InstallationType
$ansibleFacts.ansible_os_install_date = $null
if ($osInfo.InstallTime) {
$installDate = [DateTime]::FromFileTimeUtc($osInfo.InstallTime)
$ansibleFacts.ansible_os_install_date = $installDate.ToString("yyyy-MM-ddTHH:mm:ssZ")
}

# We cannot call WMI if we aren't an admin (on a network logon), conditionally set these facts.
$currentUser = [Security.Principal.WindowsPrincipal][Security.Principal.WindowsIdentity]::GetCurrent()
Expand Down

0 comments on commit 824e8d5

Please sign in to comment.