Hi,

When i executed your facts. It is throwing me error

 *irb*
*irb(main):001:0> require 'facter'*
*=> true*
*irb(main):002:0> Facter.add(:java_versions1) do*
*irb(main):003:1* setcode do*
*irb(main):004:2*  file = '/home/suppalapati/java.txt'*
*irb(main):005:2> if File.exists?('/home/suppalapati/java.txt')*
*irb(main):006:3> lines = File.readlines( file, "\n")*
*irb(main):007:3>  if ! lines.nil?*
*irb(main):008:4> versions = lines.collect {|command| `#{command.chop}`}*
*irb(main):009:4> else*
*irb(main):010:4*  versions = `java -version`.to_a*
*irb(main):011:4> end*
*irb(main):012:3> versions.join(",")*
*irb(main):013:3>  else*
*irb(main):014:3* versions = "Can't find file: #{file}"*
*irb(main):015:3>  end*
*irb(main):016:2>  end*
*irb(main):017:1>  end*
*=> #<Facter::Util::Fact:0x00000000a50320 @name=:java_versions1, 
@ldapname="java_versions1", @resolves=[], @searching=false, @value=nil>*


*Please help me*


On Wednesday, October 8, 2014 5:08:28 PM UTC-4, Corey Osman wrote:
>
> 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 puppet-users+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/puppet-users/d7171f0d-0e36-4391-83f1-51c6fa69dbb5%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to