how to use multiple strings in line.include of to use multiple if statements in puppet facts

23 views
Skip to first unread message

Spriya

unread,
Oct 28, 2014, 10:43:15 AM10/28/14
to puppet...@googlegroups.com

Hi,

I am have java text file which contains versions and as well as paths. Now i need each facts for java_path and java_version.

here is my text file where all my java information is there
/usr/lib/jvm/java-1.7.0-openjdk-1.7.0.25.x86_64/jre/bin/java
java version "1.7.0_25"
OpenJDK Runtime Environment (rhel-2.3.10.3.el6_4-x86_64)
OpenJDK 64-Bit Server VM (build 23.7-b01, mixed mode)
/usr/lib/jvm/java-1.6.0-openjdk-1.6.0.0.x86_64/jre/bin/java
java version "1.6.0_24"
OpenJDK Runtime Environment (IcedTea6 1.11.11) (rhel-1.61.1.11.11.el6_4-x86_64)
OpenJDK 64-Bit Server VM (build 20.0-b12, mixed mode)
/opt/apps/installs/srvr/source/java/jre/bin/java
java version "1.6.0_45"
Java(TM) SE Runtime Environment (build 1.6.0_45-b06)
Java HotSpot(TM) 64-Bit Server VM (build 20.45-b01, mixed mode)
/opt/apps/installs/srvr/source/java/bin/java
java version "1.6.0_45"
Java(TM) SE Runtime Environment (build 1.6.0_45-b06)
Java HotSpot(TM) 64-Bit Server VM (build 20.45-b01, mixed mode)

Here is my puppet facts

cat java_path.rb
require 'rexml/document'
require 'facter/util/file_read'
require 'facter'
require 'open3'

logfile = "/home/suppalapati/java.txt"
java_count = 0

log = Facter::Util::FileRead.read(logfile)
unless log.nil?
 log.each_line do |line|
  if line.include?('/java')
  java_count += 1
 java_path = line.split(/ /)[0]
#if line.include?("java version")
 #stdin,stdout,stderr = Open3.popen3(line)
  #java_version = stderr.readlines[0].split(/"/)[1]
  Facter.add("java_version#{java_count}_path") do
     setcode do
        java_path
       end
      end
     end
     end
    # end
  Facter.add("java_location_count") do
    setcode do
      java_count
     end
    end
    end
    #end
#Facter.add("java_version#{java_count}") do
 #     setcode do
  #        java_version
   #     end
    #    end
     #  end

Here is my java facts
java_version10_path => /opt/apps/tmp/install.dir.24660/Linux/resource/jre/bin/java
java_version11_path => /opt/apps/tmp/install.dir.2499/Linux/resource/jre/bin/java
java_version12_path => /opt/apps/tmp/install.dir.6157/Linux/resource/jre/bin/java
java_version13_path => /opt/apps/tmp/install.dir.27976/Linux/resource/jre/bin/java

How can i get java version? is there i can another if statement if line.include?('java version') or i can use use another string

Please help me



Tony Thayer

unread,
Oct 28, 2014, 1:12:57 PM10/28/14
to puppet...@googlegroups.com
Apologies if this doesn't answer your question in regards to creating custom facts, but wouldn't it make more sense to maintain this data in a profiles/roles params configuration?
- Tony
Reply all
Reply to author
Forward
0 new messages