External json fact on Windows does not work

186 views
Skip to first unread message

Miguel Di Ciurcio Filho

unread,
Dec 14, 2015, 1:38:43 PM12/14/15
to puppet...@googlegroups.com
Hi there,

I'm trying to create some external facts from PowerShell objects, e.g.:

PS> @{"foo" = "bar"; "foo2" = "bar2"} | ConvertTo-Json | Out-File
C:\ProgramData\PuppetLabs\facter\facts.d\foo.json

PS> Get-Content C:\ProgramData\PuppetLabs\facter\facts.d\foo.json
{
"foo": "bar",
"foo2": "bar2"
}

Here is error Facter shows me:

c:\Program Files\Puppet Labs\Puppet\bin>facter -v
3.1.3 (commit 1aa380a82ec35b7f8e7e58fab627e74f93aaeff3)

c:\Program Files\Puppet Labs\Puppet\bin>facter -p foo
2015-12-14 10:32:50.582395 ERROR puppetlabs.facter - error while processing "C:/
ProgramData\PuppetLabs\facter\facts.d\foo.json" for external facts: Invalid valu
e.
2015-12-14 10:32:52.425374 ERROR puppetlabs.facter - error while processing "C:/
ProgramData\PuppetLabs\facter\facts.d\foo.json" for external facts: Invalid valu
e.

I've copied the exact same json to a Linux system and it works fine.

It is me or is there a bug?

Regards,

Miguel

--
http://www.instruct.com.br - 19 2511-6506

Miguel Di Ciurcio Filho

unread,
Dec 14, 2015, 2:09:07 PM12/14/15
to puppet...@googlegroups.com
I guess I figured what it was.

The PowerShell output is UTF16 BOM, which it seams that facter cannot handle.

I changed my PowerShell script to generate simple UTF-8 and now it
works just fine.

https://en.wikipedia.org/wiki/Byte_order_mark

http://stackoverflow.com/questions/5596982/using-powershell-to-write-a-file-in-utf-8-without-the-bom
Reply all
Reply to author
Forward
0 new messages