From c075c000c82913b6422e6b7ee198675931949158 Mon Sep 17 00:00:00 2001 From: Corwin Brown Date: Wed, 28 Oct 2015 12:31:45 -0500 Subject: [PATCH] Adding Facter --- lib/ansible/modules/windows/setup.ps1 | 27 +++++++++++++++++++++++---- 1 file changed, 23 insertions(+), 4 deletions(-) diff --git a/lib/ansible/modules/windows/setup.ps1 b/lib/ansible/modules/windows/setup.ps1 index b31e76684b4..c60e8f3b9dd 100644 --- a/lib/ansible/modules/windows/setup.ps1 +++ b/lib/ansible/modules/windows/setup.ps1 @@ -41,18 +41,18 @@ foreach ($adapter in $ActiveNetcfg) default_gateway = $null interface_index = $adapter.InterfaceIndex } - + if ($adapter.defaultIPGateway) { $thisadapter.default_gateway = $adapter.DefaultIPGateway[0].ToString() } - + $formattednetcfg += $thisadapter;$thisadapter = $null } Set-Attr $result.ansible_facts "ansible_interfaces" $formattednetcfg -Set-Attr $result.ansible_facts "ansible_architecture" $win32_os.OSArchitecture +Set-Attr $result.ansible_facts "ansible_architecture" $win32_os.OSArchitecture Set-Attr $result.ansible_facts "ansible_hostname" $env:COMPUTERNAME; Set-Attr $result.ansible_facts "ansible_fqdn" "$([System.Net.Dns]::GetHostByName((hostname)).HostName)" @@ -111,9 +111,28 @@ if ($winrm_cert_thumbprint) $winrm_cert_expiry = Get-ChildItem -Path Cert:\LocalMachine\My | where Thumbprint -EQ $uppercase_cert_thumbprint | select NotAfter -if ($winrm_cert_expiry) +if ($winrm_cert_expiry) { Set-Attr $result.ansible_facts "ansible_winrm_certificate_expires" $winrm_cert_expiry.NotAfter.ToString("yyyy-MM-dd HH:mm:ss") } +# See if Facter is on the System Path +Try { + $facter_exe = Get-Command facter -ErrorAction Stop + $facter_installed = $true +} +Catch { + $facter_installed = $false +} + +# Get JSON from Facter, and parse it out. +if ($facter_installed) { + &facter -j | Tee-Object -Variable facter_output | Out-Null + $facts = "$facter_output" | ConvertFrom-Json + ForEach($fact in $facts.PSObject.Properties) { + $fact_name = $fact.Name + Set-Attr $result.ansible_facts "facter_$fact_name" $fact.Value + } +} + Exit-Json $result;