Ask Your Question
0

Powershell External Structured Facts

asked 2018-07-20 00:40:14 -0600

Ryan D gravatar image

updated 2018-07-27 01:39:53 -0600

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={
    "chocolatey.licensed":  {
                                "name":  "chocolatey.licensed",
                                "path":  "https://licensedpackages.chocolatey.org/api/v2/",
                                "adminOnly":  "False",
                                "priority":  "10",
                                "bypass":  "False",
                                "selfServiceEnabled":  "False"
                            },
    "fake":  {
                 "name":  "fake",
                 "path":  "redacted",
                 "adminOnly":  "False",
                 "priority":  "0",
                 "bypass":  "False",
                 "selfServiceEnabled":  "False"
             },
    "all":  {
                "name":  "all",
                "path":  "redacted",
                "adminOnly":  "False",
                "priority":  "0",
                "bypass":  "False",
                "selfServiceEnabled":  "True"
            },
    "soe":  {
                "name":  "soe",
                "path":  "redacted",
                "adminOnly":  "False",
                "priority":  "0",
                "bypass":  "False",
                "selfServiceEnabled":  "False"
            },
    "test":  {
                 "name":  "test",
                 "path":  "redacted",
                 "adminOnly":  "False",
                 "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
e"},"fake":{"name":"fake","path":"redacted","adminOnly":"False","priority":"0","bypass":"False","selfServiceEnabled":"False"},"all":{"name":"all","path":"redacted","adminOnly":"False","priority":"0","bypass":"False","selfServiceEnabled":"True"},"soe":{"name":"soe","path":"redacted","adminOnly":"False","priority":"0","bypass":"False","selfServiceEnabled":"False"},"test":{"name":"test","path":"redacted","adminOnly":"False","priority":"0","bypass":"False","selfServiceEnabled":"True"}}

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 flag offensive close merge delete

Comments

`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.

MichaelSmith gravatar imageMichaelSmith ( 2018-07-30 11:26:11 -0600 )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?

Branan gravatar imageBranan ( 2018-07-30 11:46:20 -0600 )edit

1 Answer

Sort by ยป oldest newest most voted
0

answered 2018-08-06 19:47:05 -0600

Ryan D gravatar image

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":  {
                         "chocolatey.licensed":  {
                                                     "name":  "chocolatey.licensed",
                                                     "path":  "https://licensedpackages.chocolatey.org/api/v2/",
                                                     "adminOnly":  "False",
                                                     "priority":  "10",
                                                     "bypass":  "False",
                                                     "selfServiceEnabled":  "False"
                                                 },
                         "all":  {
                                     "name":  "all",
                                     "path":  "",
                                     "adminOnly":  "False",
                                     "priority":  "0",
                                     "bypass":  "False",
                                     "selfServiceEnabled":  "True"
                                 },
                         "soe":  {
                                     "name":  "soe",
                                     "path":  "\",
                                     "adminOnly":  "False",
                                     "priority":  "0",
                                     "bypass":  "False",
                                     "selfServiceEnabled":  "False"
                                 },
                         "test":  {
                                      "name":  "test",
                                      "path":  "",
                                      "adminOnly":  "False",
                                      "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

edit flag offensive delete link more

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account.

Add Answer

Question Tools

1 follower

Stats

Asked: 2018-07-20 00:40:14 -0600

Seen: 488 times

Last updated: Aug 06