Yea looks like the Facter readlines method doesn't exist.

http://ruby-doc.org/core-1.8.7/IO.html#method-c-readlines

You will need to use ruby's readlines and probably clean up the lines as 
well with chop.

Revised edition:  (untested, and probably full of syntax errors)

Facter.add(:java_versions1) do
     setcode do
        file = '/home/suppalapati/java.txt'
        if File.exists?('/home/suppalapati/java.txt')
               lines = File.readlines( file, "\n")
               if ! lines.nil?
                 versions = lines.collect {|command| `#{command.chop}`}
               else
                 versions = `java -version`.to_a
              end
              versions.join(",")
       else
             # poor mans debugger
             versions = "Can't find file: #{file}"
        end
       
     end
end

Please read : https://docs.puppetlabs.com/facter/1.7/custom_facts.html

See section about loading custom facts. This will give you the chance to 
test on your machine.  

check syntax ruby -c <facter_file.rb> 
On Wednesday, October 8, 2014 12:33:55 PM UTC-7, Spriya wrote:
>
> Hi,
>
> I used the same command which you provided me
>
> Here is the code:
>
> Facter.add(:java_versions1) do
>      setcode do
>         log = Facter::Util::FileRead.readlines( 
> '/home/suppalapati/java.txt')
>         if ! log.nil?
>            versions = log.collect {|command| `#{command}`}
>         else
>            versions = `java -version`.to_a
>         end
>         versions.join(",")
>      end
> end
>
>
> Here is my 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
>
> The fact is not returning anything.
>
> Let me know
>
> On Wednesday, October 8, 2014 3:22:22 PM UTC-4, Corey Osman wrote:
>>
>>
>>
>> *I would probably do something like this where we store all the java 
>> versions in a comma separated string.Although if using facter >= 2.0 you 
>> can probably remove the join statement and store as an array.I also want to 
>> point out that java -version returns about 3 lines of text which may not be 
>> desirable. I am also not sure if Facter has a readlines  method (guessing 
>> it does), so you might have to swap out with ruby's file reading code.*
>>
>> Facter.add(:java_versions) do
>>      setcode do
>>         log = 
>> Facter::Util::FileRead.readlines( '/home/weblogic/java.txt')
>>
>> *        if ! log.nil?           versions = log.collect {|command| 
>> `#{command}`}        else           versions = `java -version`.to_a*
>> *        end         versions.join(",")     end*
>> end
>>
>>
>> Corey
>>
>> On Tuesday, October 7, 2014 10:31:12 AM UTC-7, Spriya wrote:
>>>
>>> Hi,
>>>
>>> I have a text file where i get all the java version.
>>>
>>> *cat java.txt*
>>> */usr/lib/jvm/java-1.7.0-openjdk-1.7.0.65.x86_64/jre/bin/java -version*
>>> */usr/lib/jvm/java-1.6.0-openjdk-1.6.0.0.x86_64/jre/bin/java -version*
>>> */opt/oracle/agent12c/core/12.1.0.4.0/jdk/bin/java -version*
>>> */opt/oracle/agent12c/core/12.1.0.4.0/jdk/jre/bin/java -version*
>>> */var/lib/alternatives/java -version*
>>> */u01/java/jdk1.7.0_65/jre/bin/java -version*
>>> */u01/java/jdk1.7.0_65/bin/java -version*
>>>
>>>
>>> Now i want to run commands in each line and place it in facts.
>>>
>>> How can i do that.
>>>
>>> I have just started doing the code*.*
>>>
>>>
>>>
>>>
>>>
>>>
>>>
>>> *logfile = '/home/weblogic/java.txt'line_num=0log = 
>>> Facter::Util::FileRead.read(logfile)unless log.nil?  log.each_line do 
>>> |line|  output =  Facter::Util::Resoloution.execHow can i can continue 
>>> thatPlease help me*
>>>
>>

-- 
You received this message because you are subscribed to the Google Groups 
"Puppet Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/puppet-users/cdb1ce6b-7e38-4c19-887e-66fc6a34db8c%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to