[Puppet Users] Puppetdbquery 1.1.0, now featuring hiera backendception

Erik Dalén
Mon, 27 May 2013 18:44:19 -0000

I just released dalen-puppetdbquery 1.1.0, one cool new feature in this
release is a hiera backend.

So if you have a puppet class that takes a list of hosts as a parameter you
can now fill it using dynamic data from a puppetdb query. No need anymore
to modify the module itself or create a wrapper class around it to do the
puppetdb query in.

It requires another hiera backend to be active at the same time, and that
will be used to define the actual puppetdb query to be used. It does not
matter which backend that is, there can even be several of them. To enable
add the backend `puppetdb`to the backends list in `hiera.yaml`.

So instead of writing something like this in for example your
`hiera-data/common.yaml`:

    ntp::servers:
      - ''ntp1.example.com''
      - ''ntp2.example.com''

You can now instead write:

    ntp::servers::_nodequery: ''Class[Ntp::Server]''

It will then find all nodes with the class ntp::server and return an array
containing their certname. If you instead want to return the value of a
fact, for example the `ipaddress`, the nodequery can be a query and fact
tuple, like:

    ntp::servers::_nodequery: [''Class[Ntp::Server]'',
''ipaddress'']

or a hash:

    ntp::servers::_nodequery:
      query: ''Class[Ntp::Server]''
      fact: ''ipaddress''

When returning facts only nodes that actually have the fact are returned,
even if more nodes would in fact match the query itself.

--
Erik Dalén