(MODULES-1570) java_version fact

Adapted from the many found on Github, simply runs `java -version` and strips the results. From what I can find there aren't many edge cases for the result `java -version 2>&1` could return, so this should be fairly compatible.
This commit is contained in:
Peter Souter
2014-12-05 17:35:38 +00:00
parent 378dcc7802
commit 8724592f2b

View File

@@ -0,0 +1,19 @@
# Fact: java_version
#
# Purpose: store java versions in the config DB
#
# Resolution:
# Tests for presence of java, returns nil if not present
# returns output of "java -version" and splits on \n + '"'
#
# Caveats:
# none
#
# Notes:
# None
Facter.add(:java_version) do
setcode do
t_java = Facter::Util::Resolution.exec("java -version 2>&1")
java_version = t_java.to_s.lines.first.strip.split(/version/)[1].gsub(/"/, "").strip
end
end