Hi,
currently developing / updating my setup.ps1 PR for custom facts.
`
$result = New-Object psobject @{
ansible_facts = New-Object psobject
changed = $false
}
Function Set-Attr($obj, $name, $value)
{
If the provided $obj is undefined, define one to be nice
If (-not $obj.GetType)
{
$obj = New-Object psobject
}
Try
{
$obj.$name = $value
}
Catch
{
$obj | Add-Member -Force -MemberType NoteProperty -Name $name -Value $value
}
}
Function Get-CustomFacts {
[cmdletBinding()]
param (
[Parameter(mandatory=$true)]
$factspath
)
if (-not (Test-Path -Path $factspath)) {
Fail-Json $result “The path $factspath does not exist. Typo?”
}
$FactsFiles = Get-ChildItem -Path $factspath | Where-Object -FilterScript {($PSItem.PSIsContainer -eq $false) -and ($PSItem.Extension -eq ‘.ps1’)}
foreach ($FactsFile in $FactsFiles) {
$out = . $($FactsFile.FullName)
Set-Attr $result.ansible_facts “ansible_$(($FactsFile.Name).Split(‘.’)[0])” $out
$out
}
}
Function Exit-Json($obj)
{
If the provided $obj is undefined, define one to be nice
If (-not $obj.GetType)
{
$obj = New-Object psobject
}
echo $obj | ConvertTo-Json -Compress -Depth 99
}
Get-CustomFacts -factspath ‘C:\temp’
$result
Exit-Json $result
`
Exit-Json in this case just hangs. Indefinitely.
I tested this on Windows Server 2012 R2 with PowerShell 4 and also PowerShell 5 Prod Preview.
This is the same issue I see with the win_msi module here https://github.com/ansible/ansible-modules-core/issues/2330
I had this working in 1.9.3 (hence my PR), but something lately changed. I rebuild my Ansible envs and neither 1.9.3, 1.9.4 or 2 dev branch and none of them work.
Any ideas?
All is fine up until the ConvertTo-Json call. In my tests commenting out the Depth parameter fixed my issues.
Is this something in my environment or can other people reproduce?
Also, here or Github Issue???