Skip to content

Instantly share code, notes, and snippets.

@natemccurdy
Created March 14, 2019 22:20
Show Gist options
  • Save natemccurdy/bc5386b5423ba85ae31b224b6ca4fee0 to your computer and use it in GitHub Desktop.
Save natemccurdy/bc5386b5423ba85ae31b224b6ca4fee0 to your computer and use it in GitHub Desktop.
Getting a package version from PE's package inventory feature
# PuppetDB Query method
$query = "package_inventory[package_name,version,provider] {certname = \"${facts['fqdn']}\"}"
$pkgs_from_puppetdb = puppetdb_query($query)
$bash_version_from_puppetdb = $pkgs_from_puppetdb.filter |$pkg| {$pkg['package_name'] == 'bash'}[0]['version']
notice($bash_version_from_puppetdb)
# PE Inventory Fact method
$pkgs_from_inventory_fact = $facts['_puppet_inventory_1']['packages']
$bash_version_from_inventory = $pkgs_from_inventory_fact.filter |$pkg| {$pkg[0] == 'bash'}[0][1]
notice($bash_version_from_inventory)
@natemccurdy
Copy link
Author

natemccurdy commented Mar 14, 2019

[root@pemaster ~]# puppet apply pkg_version_from_puppet.pp
Notice: Scope(Class[main]): 4.2.46-31.el7
Notice: Scope(Class[main]): 4.2.46-31.el7
Notice: Compiled catalog for pemaster.vagrant in environment production in 0.33 seconds
Notice: Applied catalog in 0.16 seconds

https://puppet.com/docs/puppetdb/6.0/api/query/v4/packages.html
https://puppet.com/docs/pe/2019.0/viewing_packages_in_use.html

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment