Forge Home

puppetdbquery

Query functions for the PuppetDB API

1,010,937 downloads

125,557 latest version

3.5 quality score

We run a couple of automated
scans to help you access a
module's quality. Each module is
given a score based on how well
the author has formatted their
code and documentation and
modules are also checked for
malware using VirusTotal.

Please note, the information below
is for guidance only and neither of
these methods should be considered
an endorsement by Puppet.

Version information

  • 3.0.1 (latest)
  • 3.0.0
  • 2.3.0
  • 2.2.0
  • 2.1.1
  • 2.1.0
  • 2.0.3
  • 2.0.2
  • 2.0.1
  • 2.0.0
  • 1.6.1
  • 1.6.0
  • 1.5.3
  • 1.5.2
  • 1.5.1
  • 1.4.0
  • 1.3.3
  • 1.3.2
  • 1.3.1
  • 1.3.0
  • 1.2.0
  • 1.1.1
  • 1.1.0
  • 1.0.4
  • 1.0.3
  • 1.0.2
  • 1.0.1
  • 1.0.0
  • 1.0.0-pre5
  • 1.0.0-pre4
  • 1.0.0-pre3
  • 1.0.0-pre2
  • 1.0.0-pre1
  • 0.1.0
  • 0.0.5
  • 0.0.4
  • 0.0.3
  • 0.0.2
  • 0.0.1
released Jun 19th 2012

Start using this module

  • r10k or Code Manager
  • Bolt
  • Manual installation
  • Direct download

Add this module to your Puppetfile:

mod 'dalen-puppetdbquery', '0.0.1'
Learn more about managing modules with a Puppetfile

Add this module to your Bolt project:

bolt module add dalen-puppetdbquery
Learn more about using this module with an existing project

Manually install this module globally with Puppet module tool:

puppet module install dalen-puppetdbquery --version 0.0.1

Direct download is not typically how you would use a Puppet module to manage your infrastructure, but you may want to download the module in order to inspect the code.

Download

Documentation

dalen/puppetdbquery — version 0.0.1 Jun 19th 2012

PuppetDB query functions

This module contains query functions for PuppetDB for use from Puppet. They require the json and rest-client ruby gems and the puppetdb-terminus.

Only queries over HTTPS are supported atm.

Usage

pdbquery

This is the generic query function that the others make use of, you probably don't have to use it and can use one of the specific functions below instead.

The first argument is the URL path that should be queried, for example 'nodes' or 'status/nodes/'. The second argument if supplied if the query parameter, if it is a string it is assumed to be JSON formatted and sent as is, anything else is converted to JSON and then sent.

Examples

# Get list of all active nodes
$ret = pdbquery('nodes', ['=', ['node', 'active'], true ])

# Query status of current node
$ret2 = pdbquery("status/nodes/${settings::certname}")

pdbresourcequery

The first argument is the resource query. Second argument is optional but allows you to specify the item you want from the returned hash.

Examples

# Return an array of hashes describing all files that are owned by root.
$ret = pdbresourcequery(
  ['and',
    ['=',['node','active'],true],
    ['=','type','File'],
    ['=',['parameter','owner'],'root']])

# Return an array of host names having those resources
$ret = pdbresourcequery(
  ['and',
    ['=',['node','active'],true],
    ['=','type','File'],
    ['=',['parameter','owner'],'root']], 'certname')

pdbnodequery

The first argument is the node query. Second argument is optional but allows you to specify a resource query that the nodes returned also have to match.

Examples

# Return an array of active nodes with an uptime more than 30 days
$ret = pdbnodequery(
  ['and',
    ['=',['node','active'],true],
    ['>',['fact','uptime_days'],30]])

# Return an array of active nodes with an uptime more than 30 days and
# having the class 'apache'
$ret = pdbnodequery(
  ['and',
    ['=',['node','active'],true],
    ['>',['fact','uptime_days'],30]],
  ['and',
    ['=',['node','active'],true],
    ['=','type','Class'],
    ['=','title','Apache']])

pdbfactquery

The first argument is the node to get facts for. Second argument is optional, if specified only return that specific fact.

Examples

# Get hash of facts for foo.example.com
pdbfactquery('foo.example.com')
# Get the uptime fact for foo.example.com
pdbfactquery('foo.example.com', 'uptime')

pdbstatusquery

The first argument is the node to get facts for. Second argument is optional, if specified only return that specific bit of status, one of 'name', 'deactivated', 'catalog_timestamp' and 'facts_timestamp'.

Examples

# Get status for foo.example.com
pdbstatusquery('foo.example.com')
# Get catalog_timestamp for foo.example.com
pdbstatusquery('foo.example.com', 'catalog_timestamp')