Skip to content

Instantly share code, notes, and snippets.

@elasticdog
Created April 24, 2013 15:00
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save elasticdog/5452797 to your computer and use it in GitHub Desktop.
Save elasticdog/5452797 to your computer and use it in GitHub Desktop.
Custom Facter facts for the installed version of Java
# Fact: javaversion & javamajversion
#
# Purpose:
# Return the version of the installed Java package in both its full form and
# just the major release version.
#
# Resolution:
# Uses the output from the `java -version` command to establish the full
# version, and then parses that value to return just the major version
# number. It will return the full javaversion if the major version could not
# be parsed out.
#
# Caveats:
#
Facter.add(:javaversion) do
setcode do
javaversion = %x[/usr/bin/java -version 2>&1 | awk '/java version/ { print $3 }'].split('"')[1]
end
end
Facter.add(:javamajversion) do
regexp = /\d+\.(\d+)\./
setcode do
javaversion = Facter.value(:javaversion)
mdata = regexp.match(javaversion)
mdata ? mdata[1] : javaversion
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment