# Powershell External Structured Facts

Hi Folks,

I'm having some issues getting my external structured fact to work with powershell. I've read through the documentation and the jira issues tracking this scenario but i still can't work out how to present my JSON to puppet. If i present my fact as pictured below, puppet will save it as "chocosources = {" and leave out the rest of the data. This seems to contradict the jira issues where this was fixed as it seems to say that if a value starts with a "{" facter/puppet will assume its JSON and appropriately treat it as a structured fact.

chocosources={
"priority":  "10",
"bypass":  "False",
"selfServiceEnabled":  "False"
},
"fake":  {
"name":  "fake",
"path":  "redacted",
"priority":  "0",
"bypass":  "False",
"selfServiceEnabled":  "False"
},
"all":  {
"name":  "all",
"path":  "redacted",
"priority":  "0",
"bypass":  "False",
"selfServiceEnabled":  "True"
},
"soe":  {
"name":  "soe",
"path":  "redacted",
"priority":  "0",
"bypass":  "False",
"selfServiceEnabled":  "False"
},
"test":  {
"name":  "test",
"path":  "redacted",
"priority":  "0",
"bypass":  "False",
"selfServiceEnabled":  "True"
}
}


if i do "-compress" the json, puppet seems to treat it as a string. At least i get all the info in, but because its a string it's effectively useless to me as a fact.

eg

chocosources={"chocolatey.licensed":{"name":"chocolatey.licensed","path":"https://licensedpackages.chocolatey.org/api/v2/","adminOnly":"False","priority":"10","bypass":"False","selfServiceEnabled":"Fals


has anybody dealt with this before?

editSo i got this working by calling my powershell script with a batch file as suggested in the Jira ticket https://tickets.puppetlabs.com/browse... . While this solution works, its pretty messy and considering the ticket says "fixed", it should be unnecessary. So the question now really becomes "am i doing it wrong? Or is this still an issue with puppet?"

thanks Ryan

edit retag close merge delete

chocosources={ isn't valid json. If the 1st example is what you were printing, I'd expect it to work if you switched to chocosources: {. I also asked to get the docs updated, because they should really include this.

( 2018-07-30 11:26:11 -0500 )edit

Powershell was missed in the original implementation of structured executable facts, because it hits a different code path. This was fixed later in https://tickets.puppetlabs.com/browse/FACT-1653. Is your Facter new enough to have that fix?

( 2018-07-30 11:46:20 -0500 )edit

Sort by » oldest newest most voted

Thanks for the response Michael!

I'm sorry i forgot to update the ticket but i managed to get the workaround working. ie. calling my ps1 with a bat. I shouldn't have really posted this version of the fact as i don't really know what i was thinking when i tried this format, i think i was just exasperated as i'd tried almost every possible format and combination i could think of. This was the original output of my script, supplying just the json object with my desired fact name as the first key in the hash. eg.

{
"chocosources":  {
"priority":  "10",
"bypass":  "False",
"selfServiceEnabled":  "False"
},
"all":  {
"name":  "all",
"path":  "",
"priority":  "0",
"bypass":  "False",
"selfServiceEnabled":  "True"
},
"soe":  {
"name":  "soe",
"path":  "\",
"priority":  "0",
"bypass":  "False",
"selfServiceEnabled":  "False"
},
"test":  {
"name":  "test",
"path":  "",
"priority":  "0",
"bypass":  "False",
"selfServiceEnabled":  "True"
}
}
}


when i tried this puppet simply ignored it entirely. I thought i was making progress when i added "chocosources=" as a string to the front because at least puppet was picking up something. But obviously this was misguided.

After reading your response i went and checked my facter version. Turns out its on 3.9.2. ugh. I'm sorry for wasting your time. I made the assumption that it was a more recent version as the bloke that installed and configured puppet for us did so after Jan this year (after the fix was deployed).

Thanks for your time and sorry it was a waste. I'll workout how to update my agents and go from there.

Ryan

more