PQL/AST: Merging query results in response on a field

8 views
Skip to first unread message

B. C.

unread,
Feb 12, 2021, 12:13:59 PM2/12/21
to Puppet Users
Dear valued community,

as I'm new to puppet as well as the community, I first of all would like to say "Hello". Secondly, I would like to say sorry if this is not the right place to ask my question.

After that being said, I would like to address my question regarding an issue on which I'm not able to make any progress - but I can imagine that for you this is not really a challenge to answer:

I do the following query using the REST-API:

----
query=["from", "package-inventory", ["extract", ["certname", "package_name","version"],["and",["~", "package_name", ".*"],["~", "certname", "^hostname0"]]]]
----

which gives the resuts like:

---
[ {
  "certname" : "hostname01",
  "package_name" : "deep_merge",
  "version" : "1.0.1"
}, {
  "certname" : " hostname01",
  "package_name" : "did_you_mean",
  "version" : "1.1.0"
}, ...
{  "certname" : " hostname02",
  "package_name" : "fast_gettext",
  "version" : "1.1.2"
},  {
  "certname" : " hostname02",
  "package_name" : "did_you_mean",
  "version" : "1.1.0"
},  ...
----

What I really would like to have as a result on the other hand is:

----
[ {
"certname" : "hostname01",
    "packages" : {
        "deep_merge" : {
            "version" : "1.0.1"
    },
        "did_you_mean" : {
            "version" : "1.1.0"
    }, ...
},
"certname" : "hostname02",
    "packages" : {
        "fast_gettext" : {
            "version" : "1.1.2"
    },
        "did_you_mean" : {
            "version" : "1.1.0"
    }, ...
}
]
---

or something equivalent to this - anyway, the main thing is that "certname" it is not being repeated für each software package and as long it's being queryable via AST (or PQL?) on the REST-API.


Thanks in advance, have a nice day & kind regards,

BCo

Reply all
Reply to author
Forward
0 new messages