From 824e8d58d7134f74045c36e0cfb05901f5051815 Mon Sep 17 00:00:00 2001 From: Jordan Borean Date: Thu, 31 Oct 2024 11:25:36 +1000 Subject: [PATCH] setup - Add ansible_os_install_date fact Adds the ansible_os_install_date fact that contains the OS installation date as an ISO 8601 string value. --- changelogs/fragments/setup-install-date.yml | 5 +++++ plugins/modules/setup.ps1 | 7 ++++++- 2 files changed, 11 insertions(+), 1 deletion(-) create mode 100644 changelogs/fragments/setup-install-date.yml diff --git a/changelogs/fragments/setup-install-date.yml b/changelogs/fragments/setup-install-date.yml new file mode 100644 index 00000000..ff67f7c8 --- /dev/null +++ b/changelogs/fragments/setup-install-date.yml @@ -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 diff --git a/plugins/modules/setup.ps1 b/plugins/modules/setup.ps1 index 03c6e689..e7f751d9 100644 --- a/plugins/modules/setup.ps1 +++ b/plugins/modules/setup.ps1 @@ -652,7 +652,7 @@ $factMeta = @( $osInfoParams = @{ LiteralPath = 'HKLM:\SOFTWARE\Microsoft\Windows NT\CurrentVersion' - Name = 'InstallationType' + Name = 'InstallationType', 'InstallTime' ErrorAction = 'SilentlyContinue' } $osInfo = Get-ItemProperty @osInfoParams @@ -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()