About | FAQ | Help
Ask Your Question

Query PuppetDB for Certain Facts

asked 2014-12-18 16:42:13 -0500

br00tal gravatar image

updated 2015-01-13 13:00:29 -0500

Hi Everyone,

First off, my apologies if this has been asked/discussed in-depth before, but I can't seem to find out much about it myself. I'm trying to use cURL to query PuppetDB around some specific system facts. I get the jist of querying, but all examples/documentation I can find always has some conditional (i.e. something like OS == CentOS) in the query logic, which is not really what I'm looking for. Simply put, I'm looking to figure out what OSes, IP addresses, kernel versions, etc. are out there in my environment. I don't want to key off any certain value of a fact, but simply return the actual values of these facts for all nodes.

Does that make sense?

To put it another way, I want to obtain the following facts (in this sort of logical structure) from PuppetDB:

  operatingsystem: RedHat
  kernel: 2.6.18-123
  operatingsystem: CentOS
  kernel: 3.10.0-2

...and so on. Any help or insight is greatly appreciated.

UPDATE 2015/01/13:

Just a quick follow-up question, is there a good way to ensure all facts are returned in the same order for all nodes? I ask, as I get different ordering for different nodes at different times, which makes parsing the output a little more difficult.

Here's an example:

# puppet query facts --render-as yaml '(fqdn~".*")' --facts ipaddress,kernel,operatingsystem,operatingsystemrelease
    operatingsystemrelease: "7.0.1406"
    kernel: Linux
    operatingsystem: CentOS
    ipaddress: ""
    operatingsystemrelease: "7.0.1406"
    kernel: Linux
    ipaddress: ""
    operatingsystem: CentOS
    ipaddress: ""
    kernel: Linux
    operatingsystemrelease: "6.6"
    operatingsystem: RedHat
    kernel: Linux
    operatingsystem: CentOS
    operatingsystemrelease: "6.6"
    ipaddress: ""

It would be very nice if they all were displayed in the order they were asked for with --facts. Thanks!

edit retag flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted

answered 2014-12-23 15:04:22 -0500

GregLarkin gravatar image

Have a look at puppetdbquery. You can use it to run queries against PuppetDB and control what the output is, like so:

# puppet query facts '(fqdn~".*")' --facts osfamily,ipaddress,kernel
host1.puppetlabs.vm  {"osfamily":"RedHat","kernel":"Linux","ipaddress":""}
host2.puppetlabs.vm  {"osfamily":"RedHat","kernel":"Linux","ipaddress":""}
host3.puppetlabs.vm  {"osfamily":"RedHat","kernel":"Linux","ipaddress":""}
host4.puppetlabs.vm  {"osfamily":"RedHat","kernel":"Linux","ipaddress":""}
host5.puppetlabs.vm  {"osfamily":"RedHat","kernel":"Linux","ipaddress":""}

In my example, I'm effectively selecting all nodes by performing a regexp search against all fqdn facts containing zero or more characters. You can easily restrict that condition as needed, and there are examples in the puppetdbquery README file.

edit flag offensive delete link more


Thanks! I was looking into puppetdbquery, but for whatever reason at the time, I decided it wasn't the way I wanted to go. Based on further research, and your input/example, it does almost exactly what I'm looking for. Thanks again!

br00tal gravatar imagebr00tal ( 2014-12-26 08:38:57 -0500 )edit

Glad to help, and if you wouldn't mind marking my answer as correct, I would appreciate it. Thank you!

GregLarkin gravatar imageGregLarkin ( 2014-12-26 13:03:20 -0500 )edit

Your Answer

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

Add Answer

Question Tools



Asked: 2014-12-18 16:42:13 -0500

Seen: 1,073 times

Last updated: Jan 13 '15