From e74d397c01a571285a007e996af7a24b8d69d833 Mon Sep 17 00:00:00 2001 From: Shachaf92 Date: Wed, 13 Nov 2019 01:05:16 +0200 Subject: [PATCH] setup.ps1 - parity with linux regarding missing local facts path (#58887) * setup.ps1 - parity with linux regarding missing local facts path * add warning * Update setup.ps1-parity-with-linux-regarding-missing-local-facts-path.yml --- ...inux-regarding-missing-local-facts-path.yml | 2 ++ lib/ansible/modules/windows/setup.ps1 | 18 ++++++++++-------- 2 files changed, 12 insertions(+), 8 deletions(-) create mode 100644 changelogs/fragments/setup.ps1-parity-with-linux-regarding-missing-local-facts-path.yml diff --git a/changelogs/fragments/setup.ps1-parity-with-linux-regarding-missing-local-facts-path.yml b/changelogs/fragments/setup.ps1-parity-with-linux-regarding-missing-local-facts-path.yml new file mode 100644 index 0000000000..e43747c238 --- /dev/null +++ b/changelogs/fragments/setup.ps1-parity-with-linux-regarding-missing-local-facts-path.yml @@ -0,0 +1,2 @@ +minor_changes: +- "setup.ps1 - parity with linux regarding missing local facts path (https://github.com/ansible/ansible/issues/57974)" diff --git a/lib/ansible/modules/windows/setup.ps1 b/lib/ansible/modules/windows/setup.ps1 index 652d2b0b72..3422163d88 100644 --- a/lib/ansible/modules/windows/setup.ps1 +++ b/lib/ansible/modules/windows/setup.ps1 @@ -12,15 +12,17 @@ Function Get-CustomFacts { $factpath = $null ) - if (-not (Test-Path -Path $factpath)) { - Fail-Json $result "The path $factpath does not exist. Typo?" + if (Test-Path -Path $factpath) { + $FactsFiles = Get-ChildItem -Path $factpath | Where-Object -FilterScript {($PSItem.PSIsContainer -eq $false) -and ($PSItem.Extension -eq '.ps1')} + + foreach ($FactsFile in $FactsFiles) { + $out = & $($FactsFile.FullName) + $result.ansible_facts.Add("ansible_$(($FactsFile.Name).Split('.')[0])", $out) + } } - - $FactsFiles = Get-ChildItem -Path $factpath | Where-Object -FilterScript {($PSItem.PSIsContainer -eq $false) -and ($PSItem.Extension -eq '.ps1')} - - foreach ($FactsFile in $FactsFiles) { - $out = & $($FactsFile.FullName) - $result.ansible_facts.Add("ansible_$(($FactsFile.Name).Split('.')[0])", $out) + else + { + Add-Warning $result "Non existing path was set for local facts - $factpath" } }