Skip to content

Instantly share code, notes, and snippets.

@binford2k
Created August 17, 2018 05:20
Show Gist options
  • Save binford2k/3ddb6614665f63a97f7dba3f85f31814 to your computer and use it in GitHub Desktop.
Save binford2k/3ddb6614665f63a97f7dba3f85f31814 to your computer and use it in GitHub Desktop.
/usr/local/bin/facter
#! /usr/bin/env ruby
require 'json'
ENV['facter_cache'] ||= `/opt/puppetlabs/bin/facter --show-legacy --no-external-facts --json`
cache = JSON.parse(ENV['facter_cache']) rescue {}
value = ARGV.first.split('.').reduce(cache) do |collector, key|
break unless collector.keys.include? key
collector[key]
end
value ||= `/opt/puppetlabs/bin/facter --show-legacy --puppet #{ARGV.first}`
print value
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment