I''ve created a set of functions that exposes the PuppetDB query API from inside puppet. Feel free to give them a spin and get back to me with any bugs or feedback. https://github.com/dalen/puppet-puppetdbquery They require ruby-restclient, ruby-json and the puppetdb-terminus. To give you an example of a query you can do inside puppet code using these functions and PuppetDB: # Return an array of active nodes with an uptime more than 30 days and # having the class ''apache'' $hosts = pdbnodequery([ ''and'', [ ''='', [ ''node'', ''active'' ], true ], [''>'', [ ''fact'', ''uptime_days'' ], 30 ] ], [ ''and'', [ ''='', ''type'', ''Class'' ], [ ''='', ''title'', ''Apache'' ] ] )" This can be used for example to populate lists of nodes behind load balancers and such dynamically instead of writing them down in your puppet code. -- Erik Dalén -- You received this message because you are subscribed to the Google Groups "Puppet Users" group. To post to this group, send email to puppet-users@googlegroups.com. To unsubscribe from this group, send email to puppet-users+unsubscribe@googlegroups.com. For more options, visit this group at http://groups.google.com/group/puppet-users?hl=en.
On 19.06.2012 16:48, Erik Dalén wrote:> I''ve created a set of functions that exposes the PuppetDB query API > from inside puppet. Feel free to give them a spin and get back to me > with any bugs or feedback. > > https://github.com/dalen/puppet-puppetdbquery > > They require ruby-restclient, ruby-json and the puppetdb-terminus. > > To give you an example of a query you can do inside puppet code using > these functions and PuppetDB: > > # Return an array of active nodes with an uptime more than 30 days and > # having the class ''apache'' > $hosts = pdbnodequery([ ''and'', [ ''='', [ ''node'', ''active'' ], true ], > [''>'', [ ''fact'', ''uptime_days'' ], 30 ] ], > [ ''and'', [ ''='', ''type'', ''Class'' ], [ ''='', ''title'', ''Apache'' ] ] )" > > This can be used for example to populate lists of nodes behind load > balancers and such dynamically instead of writing them down in your > puppet code.Nice! Do you have any number comparing the performance of this against collection of a similar amount of resources by the puppetmaster? Best Regards, David -- You received this message because you are subscribed to the Google Groups "Puppet Users" group. To post to this group, send email to puppet-users@googlegroups.com. To unsubscribe from this group, send email to puppet-users+unsubscribe@googlegroups.com. For more options, visit this group at http://groups.google.com/group/puppet-users?hl=en.
On 19 June 2012 16:55, David Schmitt <david@dasz.at> wrote:> On 19.06.2012 16:48, Erik Dalén wrote: >> >> I''ve created a set of functions that exposes the PuppetDB query API >> from inside puppet. Feel free to give them a spin and get back to me >> with any bugs or feedback. >> >> https://github.com/dalen/puppet-puppetdbquery >> >> They require ruby-restclient, ruby-json and the puppetdb-terminus. >> >> To give you an example of a query you can do inside puppet code using >> these functions and PuppetDB: >> >> # Return an array of active nodes with an uptime more than 30 days and >> # having the class ''apache'' >> $hosts = pdbnodequery([ ''and'', [ ''='', [ ''node'', ''active'' ], true ], >> [''>'', [ ''fact'', ''uptime_days'' ], 30 ] ], >> [ ''and'', [ ''='', ''type'', ''Class'' ], [ ''='', ''title'', ''Apache'' ] ] )" >> >> This can be used for example to populate lists of nodes behind load >> balancers and such dynamically instead of writing them down in your >> puppet code. > > > Nice! Do you have any number comparing the performance of this against > collection of a similar amount of resources by the puppetmaster? >Not entirely sure I know what you mean, but it should be a lot faster than parsing through cached catalogs searching for matching nodes if that''s what you mean? So far I haven''t done any extensive performance testing on PuppetDB, I think the puppetlabs guys have though with good results. The performance hit from these functions themselves if any would be in parsing the returned JSON and handing that back to puppet, but the time consumed for that should be minimal. -- Erik Dalén -- You received this message because you are subscribed to the Google Groups "Puppet Users" group. To post to this group, send email to puppet-users@googlegroups.com. To unsubscribe from this group, send email to puppet-users+unsubscribe@googlegroups.com. For more options, visit this group at http://groups.google.com/group/puppet-users?hl=en.
Deepak Giridharagopal
2012-Jun-19 15:39 UTC
Re: [Puppet Users] Query functions for PuppetDB
On Tue, Jun 19, 2012 at 9:55 AM, David Schmitt <david@dasz.at> wrote:> On 19.06.2012 16:48, Erik Dalén wrote: > >> I''ve created a set of functions that exposes the PuppetDB query API >> from inside puppet. Feel free to give them a spin and get back to me >> with any bugs or feedback. >> >> https://github.com/dalen/**puppet-puppetdbquery<https://github.com/dalen/puppet-puppetdbquery> >> >> They require ruby-restclient, ruby-json and the puppetdb-terminus. >> >> To give you an example of a query you can do inside puppet code using >> these functions and PuppetDB: >> >> # Return an array of active nodes with an uptime more than 30 days and >> # having the class ''apache'' >> $hosts = pdbnodequery([ ''and'', [ ''='', [ ''node'', ''active'' ], true ], >> [''>'', [ ''fact'', ''uptime_days'' ], 30 ] ], >> [ ''and'', [ ''='', ''type'', ''Class'' ], [ ''='', ''title'', ''Apache'' ] ] )" >> >> This can be used for example to populate lists of nodes behind load >> balancers and such dynamically instead of writing them down in your >> puppet code. >> > > Nice! Do you have any number comparing the performance of this against > collection of a similar amount of resources by the puppetmaster? >Looking at the code, it''s issuing queries against the same HTTP endpoint as the PuppetDB resource terminus. For the same query, it should perform (quite literally) exactly the same; the functions are getting the same data in the same way from the same place. Keep in mind, though, that these functions allow for more advanced queries than collection syntax currently allows: arbitrarily nested booleans, you can query for things other than resources, you can query across types, etc. So it''s not _quite_ apples-to-apples. :) deepak -- Deepak Giridharagopal / Puppet Labs / grim_radical -- You received this message because you are subscribed to the Google Groups "Puppet Users" group. To post to this group, send email to puppet-users@googlegroups.com. To unsubscribe from this group, send email to puppet-users+unsubscribe@googlegroups.com. For more options, visit this group at http://groups.google.com/group/puppet-users?hl=en.
Deepak Giridharagopal
2012-Jun-19 15:43 UTC
Re: [Puppet Users] Query functions for PuppetDB
On Tue, Jun 19, 2012 at 9:48 AM, Erik Dalén <erik.gustav.dalen@gmail.com>wrote:> I''ve created a set of functions that exposes the PuppetDB query API > from inside puppet. Feel free to give them a spin and get back to me > with any bugs or feedback. > > https://github.com/dalen/puppet-puppetdbquery > > They require ruby-restclient, ruby-json and the puppetdb-terminus. > > To give you an example of a query you can do inside puppet code using > these functions and PuppetDB: > > # Return an array of active nodes with an uptime more than 30 days and > # having the class ''apache'' > $hosts = pdbnodequery([ ''and'', [ ''='', [ ''node'', ''active'' ], true ], > [''>'', [ ''fact'', ''uptime_days'' ], 30 ] ], > [ ''and'', [ ''='', ''type'', ''Class'' ], [ ''='', ''title'', ''Apache'' ] ] )" > > This can be used for example to populate lists of nodes behind load > balancers and such dynamically instead of writing them down in your > puppet code. >This is fantastic, Erik! deepak -- Deepak Giridharagopal / Puppet Labs / grim_radical -- You received this message because you are subscribed to the Google Groups "Puppet Users" group. To post to this group, send email to puppet-users@googlegroups.com. To unsubscribe from this group, send email to puppet-users+unsubscribe@googlegroups.com. For more options, visit this group at http://groups.google.com/group/puppet-users?hl=en.
I''ve released a new version of this module, it no longer requires the rest_client gem and uses the Puppet HTTP pool instead. It also supports getting facts for an array of hosts at once. As an example if you want the IPs of all hosts with Apache class you could do this: $hosts = pdbfactquery(pdbresourcequery([ ''and'', [ ''='', [ ''node'', ''active'' ], true ], [ ''='', ''type'', ''Class'' ], [ ''='', ''title'', ''Apache'' ] ], ''certname''), ''ipaddress'') It is also on the Puppet Forge now: http://forge.puppetlabs.com/dalen/puppetdbquery On 19 June 2012 16:48, Erik Dalén <erik.gustav.dalen@gmail.com> wrote:> I''ve created a set of functions that exposes the PuppetDB query API > from inside puppet. Feel free to give them a spin and get back to me > with any bugs or feedback. > > https://github.com/dalen/puppet-puppetdbquery > > They require ruby-restclient, ruby-json and the puppetdb-terminus. > > To give you an example of a query you can do inside puppet code using > these functions and PuppetDB: > > # Return an array of active nodes with an uptime more than 30 days and > # having the class ''apache'' > $hosts = pdbnodequery([ ''and'', [ ''='', [ ''node'', ''active'' ], true ], > [''>'', [ ''fact'', ''uptime_days'' ], 30 ] ], > [ ''and'', [ ''='', ''type'', ''Class'' ], [ ''='', ''title'', ''Apache'' ] ] )" > > This can be used for example to populate lists of nodes behind load > balancers and such dynamically instead of writing them down in your > puppet code. > > -- > Erik Dalén-- Erik Dalén -- You received this message because you are subscribed to the Google Groups "Puppet Users" group. To post to this group, send email to puppet-users@googlegroups.com. To unsubscribe from this group, send email to puppet-users+unsubscribe@googlegroups.com. For more options, visit this group at http://groups.google.com/group/puppet-users?hl=en.
Martin Willemsma
2012-Jul-19 21:28 UTC
Re: [Puppet Users] Re: Query functions for PuppetDB
2012/7/19 Erik Dalén <erik.gustav.dalen@gmail.com>:> I''ve released a new version of this module, it no longer requires the > rest_client gem and uses the Puppet HTTP pool instead. > It also supports getting facts for an array of hosts at once. As an > example if you want the IPs of all hosts with Apache class you could > do this: > > $hosts = pdbfactquery(pdbresourcequery([ ''and'', [ ''='', [ ''node'', > ''active'' ], true ], [ ''='', ''type'', ''Class'' ], [ ''='', ''title'', ''Apache'' > ] ], ''certname''), ''ipaddress'') > > It is also on the Puppet Forge now: > http://forge.puppetlabs.com/dalen/puppetdbquery > > On 19 June 2012 16:48, Erik Dalén <erik.gustav.dalen@gmail.com> wrote: >> I''ve created a set of functions that exposes the PuppetDB query API >> from inside puppet. Feel free to give them a spin and get back to me >> with any bugs or feedback. >> >> https://github.com/dalen/puppet-puppetdbquery >> >> They require ruby-restclient, ruby-json and the puppetdb-terminus. >> >> To give you an example of a query you can do inside puppet code using >> these functions and PuppetDB: >> >> # Return an array of active nodes with an uptime more than 30 days and >> # having the class ''apache'' >> $hosts = pdbnodequery([ ''and'', [ ''='', [ ''node'', ''active'' ], true ], >> [''>'', [ ''fact'', ''uptime_days'' ], 30 ] ], >> [ ''and'', [ ''='', ''type'', ''Class'' ], [ ''='', ''title'', ''Apache'' ] ] )" >> >> This can be used for example to populate lists of nodes behind load >> balancers and such dynamically instead of writing them down in your >> puppet code. >> >> -- >> Erik Dalén > > > > -- > Erik Dalén > > -- > You received this message because you are subscribed to the Google Groups "Puppet Users" group. > To post to this group, send email to puppet-users@googlegroups.com. > To unsubscribe from this group, send email to puppet-users+unsubscribe@googlegroups.com. > For more options, visit this group at http://groups.google.com/group/puppet-users?hl=en. >Hi Erik, This is cool! Nice job. I''m going to play with this -- --- Kind regards, Martin Willemsma -- You received this message because you are subscribed to the Google Groups "Puppet Users" group. To post to this group, send email to puppet-users@googlegroups.com. To unsubscribe from this group, send email to puppet-users+unsubscribe@googlegroups.com. For more options, visit this group at http://groups.google.com/group/puppet-users?hl=en.
On Thursday, July 19, 2012 10:02:32 AM UTC-7, Erik Dalén wrote:> It also supports getting facts for an array of hosts at once. As an > example if you want the IPs of all hosts with Apache class you could > do this: > > $hosts = pdbfactquery(pdbresourcequery([ ''and'', [ ''='', [ ''node'', > ''active'' ], true ], [ ''='', ''type'', ''Class'' ], [ ''='', ''title'', ''Apache'' > ] ], ''certname''), ''ipaddress'') > >WOWWW, that is extremely cool. I can see all kinds of uses for that. -- You received this message because you are subscribed to the Google Groups "Puppet Users" group. To view this discussion on the web visit https://groups.google.com/d/msg/puppet-users/-/3jYj7blNAwkJ. To post to this group, send email to puppet-users@googlegroups.com. To unsubscribe from this group, send email to puppet-users+unsubscribe@googlegroups.com. For more options, visit this group at http://groups.google.com/group/puppet-users?hl=en.
Deepak Giridharagopal
2012-Jul-20 00:27 UTC
Re: [Puppet Users] Re: Query functions for PuppetDB
On Thu, Jul 19, 2012 at 07:02:32PM +0200, Erik Dalén <erik.gustav.dalen@gmail.com> wrote:> I''ve released a new version of this module, it no longer requires the > rest_client gem and uses the Puppet HTTP pool instead. > It also supports getting facts for an array of hosts at once. As an > example if you want the IPs of all hosts with Apache class you could > do this: > > $hosts = pdbfactquery(pdbresourcequery([ ''and'', [ ''='', [ ''node'', > ''active'' ], true ], [ ''='', ''type'', ''Class'' ], [ ''='', ''title'', ''Apache'' > ] ], ''certname''), ''ipaddress'')Awesome! deepak -- Deepak Giridharagopal / Puppet Labs / grim_radical -- You received this message because you are subscribed to the Google Groups "Puppet Users" group. To post to this group, send email to puppet-users@googlegroups.com. To unsubscribe from this group, send email to puppet-users+unsubscribe@googlegroups.com. For more options, visit this group at http://groups.google.com/group/puppet-users?hl=en.
Very cool! My brain has extrapolated a few cool uses already. :) Thanks Erik! On 20 July 2012 03:02, Erik Dalén <erik.gustav.dalen@gmail.com> wrote:> I''ve released a new version of this module, it no longer requires the > rest_client gem and uses the Puppet HTTP pool instead. > It also supports getting facts for an array of hosts at once. As an > example if you want the IPs of all hosts with Apache class you could > do this: > > $hosts = pdbfactquery(pdbresourcequery([ ''and'', [ ''='', [ ''node'', > ''active'' ], true ], [ ''='', ''type'', ''Class'' ], [ ''='', ''title'', ''Apache'' > ] ], ''certname''), ''ipaddress'') > > It is also on the Puppet Forge now: > http://forge.puppetlabs.com/dalen/puppetdbquery > > On 19 June 2012 16:48, Erik Dalén <erik.gustav.dalen@gmail.com> wrote: >> I''ve created a set of functions that exposes the PuppetDB query API >> from inside puppet. Feel free to give them a spin and get back to me >> with any bugs or feedback. >> >> https://github.com/dalen/puppet-puppetdbquery >> >> They require ruby-restclient, ruby-json and the puppetdb-terminus. >> >> To give you an example of a query you can do inside puppet code using >> these functions and PuppetDB: >> >> # Return an array of active nodes with an uptime more than 30 days and >> # having the class ''apache'' >> $hosts = pdbnodequery([ ''and'', [ ''='', [ ''node'', ''active'' ], true ], >> [''>'', [ ''fact'', ''uptime_days'' ], 30 ] ], >> [ ''and'', [ ''='', ''type'', ''Class'' ], [ ''='', ''title'', ''Apache'' ] ] )" >> >> This can be used for example to populate lists of nodes behind load >> balancers and such dynamically instead of writing them down in your >> puppet code. >> >> -- >> Erik Dalén > > > > -- > Erik Dalén > > -- > You received this message because you are subscribed to the Google Groups "Puppet Users" group. > To post to this group, send email to puppet-users@googlegroups.com. > To unsubscribe from this group, send email to puppet-users+unsubscribe@googlegroups.com. > For more options, visit this group at http://groups.google.com/group/puppet-users?hl=en. >-- You received this message because you are subscribed to the Google Groups "Puppet Users" group. To post to this group, send email to puppet-users@googlegroups.com. To unsubscribe from this group, send email to puppet-users+unsubscribe@googlegroups.com. For more options, visit this group at http://groups.google.com/group/puppet-users?hl=en.