PQL, puppetdb and tags set with tag()

147 views
Skip to first unread message

R.I.Pienaar

unread,
Jul 31, 2016, 6:05:45 PM7/31/16
to puppet-dev
hello,

I am trying to selectively find classes using PQL that has a certain parameter.

class foo($server=true) {
}

So with PQL I have no idea how to match only foo classes where server = true, it
appears from errors that it does support search parameters but nothing in the
docs and I can't figure it out.

So then I tried to query via tags which does work, I figured I'll ta the
class using tag():

class foo($server=true) {
if $server {
tag("foo_server")
}

if tagged("foo_server") {
notify{"it's tagged": }
}
}

this code runs, and the notify fires, however if I query puppet db using a simple
resources {type = "Class" and title = "Foo"} the tag set with the function does not
appear on the class.

So back to not having anyway to find nodes where foo::server = true, any ideas?

---
R.I.Pienaar

Ryan Whitehurst

unread,
Aug 2, 2016, 12:05:06 PM8/2/16
to puppe...@googlegroups.com
On Sun, Jul 31, 2016 at 3:05 PM, R.I.Pienaar <r...@devco.net> wrote:
> hello,
>
> I am trying to selectively find classes using PQL that has a certain parameter.
>
> class foo($server=true) {
> }
>
> So with PQL I have no idea how to match only foo classes where server = true, it
> appears from errors that it does support search parameters but nothing in the
> docs and I can't figure it out.

In the current version of PQL, you can't query against parameters.
It's under development though:
https://github.com/puppetlabs/puppetdb/pull/2000

In the future, you should be able to query parameters with

resources { type = "Class" and title = "Foo" and parameters.server = true }

What you can do now, however, is use the AST query language:

["from", "resources",
["and",
["=", "type", "Class"],
["=", "title", "Foo"],
["=", ["parameter", "server"], true]]]

This will do the same thing as the PQL except it works in the current
version of PuppetDB. It's not quite as convenient, but at least it
works.

> So then I tried to query via tags which does work, I figured I'll ta the
> class using tag():
>
> class foo($server=true) {
> if $server {
> tag("foo_server")
> }
>
> if tagged("foo_server") {
> notify{"it's tagged": }
> }
> }
>
> this code runs, and the notify fires, however if I query puppet db using a simple
> resources {type = "Class" and title = "Foo"} the tag set with the function does not
> appear on the class.
>
> So back to not having anyway to find nodes where foo::server = true, any ideas?
>
> ---
> R.I.Pienaar
>
> --
> You received this message because you are subscribed to the Google Groups "Puppet Developers" group.
> To unsubscribe from this group and stop receiving emails from it, send an email to puppet-dev+...@googlegroups.com.
> To view this discussion on the web visit https://groups.google.com/d/msgid/puppet-dev/994494591.394148.1470002741906.JavaMail.zimbra%40devco.net.
> For more options, visit https://groups.google.com/d/optout.

R.I.Pienaar

unread,
Aug 2, 2016, 12:10:25 PM8/2/16
to puppet-dev
Thanks, alas I have giant PQL queries so can't really mix and match just this part
and don't want to make many queries :(

Thanks though.

Odd about the tags stuff, but I found a way to get what I need with tags
Reply all
Reply to author
Forward
0 new messages