Created
November 2, 2017 12:23
-
-
Save abuxton/4c8b718a7effa281a952d4700359cd55 to your computer and use it in GitHub Desktop.
using PQL with Package discovery in Puppet DSL
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
## | |
# example of how to use puppet package inventory to manage a package on a puppetized host. | |
# once puppet package inventory is populated puppet query langauge used puppetdb_query() | |
# version comparison is used to manage resource decleration | |
# querying a canary or example host can be used to drive patching this way | |
## | |
$cowsay_query = "package_inventory{ certname = '$fqdn' and package_name = 'cowsay' }" | |
# expected output on test machine | |
#[ | |
# { | |
# "certname": "master.puppetlabs.vm", | |
# "package_name": "cowsay", | |
# "version": "3.04-4.el7", | |
# "provider": "yum" | |
# } | |
#] | |
$package = puppetdb_query($cowsay_query) | |
#notify {"package info for $package":} #just to prove the output | |
$version = lookup('package_version') #package_version: '3.04-4.el7' | |
#if "$package['version']" !~ $version { | |
if "$package['version']" !~ '3.04-4.el7' { | |
package{'cowsay': | |
ensure => '3.04-4.el7', #$version | |
noop => true, #only noop to ensure safe testing | |
} | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment