Last active
August 15, 2017 22:01
-
-
Save purplexa/9db13b7385032a68f760148eab9baf46 to your computer and use it in GitHub Desktop.
PDB class node inventory
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function myorg::pdb::class_node_inventory ( | |
Pattern['\A[A-Za-z][A-Za-z0-9]*(::[A-Za-z][A-Za-z0-9]*)*\Z'] $classname, | |
Optional[String[1]] $env = undef, | |
) { | |
$query_template = @(EOT) | |
<%- | String $classname, | |
Optional[String] $env, | |
| -%> | |
inventory { | |
<%- if $env { -%> | |
facts.environment = "<%= $env %>" and | |
<%- } -%> | |
certname in resources [certname] { | |
type = "Class" and | |
title = "<%= $classname %>" | |
} and | |
certname in nodes [certname] { | |
deactivated is null and | |
expired is null | |
} | |
} | |
|- EOT | |
$formatted_classname = $classname.split('::').capitalize().join('::') | |
$query = $query_template.inline_epp({ | |
classname => $formatted_classname, | |
env => $env, | |
}) | |
$results = puppetdb_query($query) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment