Last active
August 4, 2017 19:55
-
-
Save robbyt/55acdc70182c634ec4c6880a0df41e12 to your computer and use it in GitHub Desktop.
Custom fact for finding the version of java installed
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
Facter.add(:java) do | |
confine :kernel => "Linux" | |
regexp = /\d+\.(\d+)\./ | |
setcode do | |
java = {} | |
java['path'] = Facter::Core::Execution.which('java') | |
if java['path'] != nil | |
p = java['path'] | |
v = Facter::Core::Execution.exec("#{p} -version 2>&1").lines.first.split('"') | |
if v != nil | |
if v.length >= 1 | |
v = v[1] | |
end | |
end | |
java['version'] = v | |
else | |
Facter.debug("Java not in path!") | |
end | |
if java['version'] != nil | |
mdata = regexp.match(java['version']) | |
if mdata != nil | |
java['major_version'] = mdata[1] | |
end | |
end | |
if java | |
java | |
else | |
nil | |
end | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment