Skip to content

Instantly share code, notes, and snippets.

@purplexa
Last active August 15, 2017 22:01
Show Gist options
  • Save purplexa/9db13b7385032a68f760148eab9baf46 to your computer and use it in GitHub Desktop.
Save purplexa/9db13b7385032a68f760148eab9baf46 to your computer and use it in GitHub Desktop.
PDB class node inventory
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