Skip to content

Instantly share code, notes, and snippets.

@robbyt
Last active August 4, 2017 19:55
Show Gist options
  • Save robbyt/55acdc70182c634ec4c6880a0df41e12 to your computer and use it in GitHub Desktop.
Save robbyt/55acdc70182c634ec4c6880a0df41e12 to your computer and use it in GitHub Desktop.
Custom fact for finding the version of java installed
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