how to write each java version to individual facts

46 views
Skip to first unread message

Spriya

unread,
Oct 8, 2014, 2:41:24 PM10/8/14
to puppet...@googlegroups.com
Hi All,

I am trying to get all the java versions and paths where it is located. I got all java_paths in a fact called java_path. Now i need those versions in each custom facts.

I wrote a code but this not executing .

Please help me

require 'rexml/document'
require 'facter'

Facter.add("java_path") do
  setcode do
    Facter::Util::Resolution.exec('/home/suppalapati/java.sh')
    end
end




logfile = '/home/suppalapati/java.txt'

line_num=0

log = Facter::Util::FileRead.read(logfile)
unless log.nil?
  log.each_line do |line|
    if line.include?('java')
       line_num += 1
       javaid, val =  %x[ #{log} ]
    Facter.add("java_#{javaid}") do
      setcode do
         val
        end
       end
     end
   end

 Facter.add("java_version_count") do
  setcode do
    line_num
  end
 end
end


Here is my java.txt file

/usr/java/jre1.7.0_51/bin/java
/usr/lib/jvm/java-1.6.0-openjdk-1.6.0.0.x86_64/jre/bin/java
/opt/CLM-Web-Tools/im/linux.gtk.x86_64/jre_6.0.0.sr9_20110208_03/jre/bin/java
/opt/CLM-Web-Tools/im/linux.gtk.x86/jre_6.0.0.sr9_20110208_03/jre/bin/java
/opt/IBM/TeamConcertBuild/jre/bin/java
/opt/IBM/InstallationManager/eclipse/jre_6.0.0.sr9_20110208_03/jre/bin/java
/opt/IBM/InstallationManager_old/InstallationManager_old/eclipse/jre_6.0.0.sr9_20110208_03/jre/bin/java
/opt/IBM/TeamConcertBuild_old/jre/bin/java
/opt/itm/v6.2.2/JRE/lx8266/bin/java
/var/lib/alternatives/java
/u01/app/oracle/product/jdk1.7.0_25/jre/bin/java
/u01/app/oracle/product/jdk1.7.0_25/bin/java


Please help me

Felix Frank

unread,
Oct 31, 2014, 5:49:00 AM10/31/14
to puppet...@googlegroups.com
On 10/08/2014 08:41 PM, Spriya wrote:
> Hi All,
>
> I am trying to get all the java versions and paths where it is located.
> I got all java_paths in a fact called java_path. Now i need those
> versions in each custom facts.
>
> I wrote a code but this not executing .

Hi,

has this been resolved in one of your more recent threads? Or is it
still an issue?
Reply all
Reply to author
Forward
0 new messages