is there anyway to merge two facts into single one

38 views
Skip to first unread message

Spriya

unread,
Nov 20, 2014, 1:21:09 PM11/20/14
to puppet...@googlegroups.com
Hi ,

Is there any way to merge two facts into single facts.

Here is my facts
java_known_weblogic_version11.7.0_72
java_known_weblogic_version1_path/u01/java/jdk1.7.0_72/jre/bin/java


I want to merge these two facts into single one 

I mean 

java_known_weblogic_version1 = 1.7.0_72//u01/java/jdk1.7.0_72/jre/bin/java

Like this

Anyone please help me

jcbollinger

unread,
Nov 21, 2014, 8:58:53 AM11/21/14
to puppet...@googlegroups.com


In what context, for what purpose?

Generally speaking, I'd say you should just concatenate the two fact values in the scope where the aggregate value is wanted, as opposed to modifying fact implementations to change what facter reports.  Is that unsuitable for some reason?


John

Spriya

unread,
Nov 21, 2014, 9:40:44 AM11/21/14
to puppet...@googlegroups.com

Hi,

The purpose  is i want to compare using the value to a txt file which contains 1.7.0_72//u01/java/jdk1.7.0_72/jre/bin/java this reason for that i want to concatenate.

Let me know your thoughts

Zachary Stern

unread,
Nov 21, 2014, 1:41:16 PM11/21/14
to puppet...@googlegroups.com
If you have a fact called factA and a fact called factB, and you need factC to be a combination of both values, sure, that can be done.

I don't know what version of Facter you're using, but if you're using PE 3.7 + Facter 2.2.0, you can simply use Facter.value.

E.g:

Facter.add(:factC) do
  setcode do
    factC = "#{Facter.value('factA')}#{Facter.value('factB')}"
    factC
  end
end

That would return a factC that was the combined values of factA and factB.


You could of course just combine the fact values in your puppet code as well, if that's appropriate...

`$value = "${one}${two}"` is perfectly valid Puppet code.

Spriya

unread,
Nov 21, 2014, 2:07:42 PM11/21/14
to puppet...@googlegroups.com
Thank you

Spriya

unread,
Nov 26, 2014, 1:25:12 PM11/26/14
to puppet...@googlegroups.com
Hi,

When i am concatenating using your method. Its only returning one values. It should have version in front of  path

Facter.add("java_foundversion#{java_count}_foundversion#{java_count}_path") do
 setcode do
    java_version[1] + java_path
end
end


The output of facts 
/opt/puppet/bin/facter -p | grep -i java_*        java_foundversion1_path => /usr/lib/jvm/java-1.7.0-openjdk-1.7.0.65.x86_64/jre/bin/java
java_foundversion2_path => /usr/lib/jvm/java-1.6.0-openjdk-1.6.0.0.x86_64/jre/bin/java
java_foundversion3_path => /opt/oracle/agent12c/core/12.1.0.4.0/jdk/bin/java
java_foundversion4_path => /opt/oracle/agent12c/core/12.1.0.4.0/jdk/jre/bin/java
java_foundversion5_path => /opt/itm/v6.2.2/JRE/lx8266/bin/java
java_foundversion6_path => /u01/java/jdk1.7.0_72/jre/bin/java
java_foundversion7_path => /u01/java/jdk1.7.0_72/bin/java
java_foundversion8_path => /u01/java/jdk1.7.0_65/jre/bin/java
java_foundversion9_path => /u01/java/jdk1.7.0_65/bin/java




On Friday, November 21, 2014 1:41:16 PM UTC-5, Zachary Stern wrote:

Zachary Stern

unread,
Nov 26, 2014, 1:57:23 PM11/26/14
to puppet...@googlegroups.com
If that's happening, then one of the facts must be returning nil.

--
You received this message because you are subscribed to a topic in the Google Groups "Puppet Users" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/puppet-users/CgskLngu_yY/unsubscribe.
To unsubscribe from this group and all its topics, send an email to puppet-users...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/puppet-users/742fb742-5020-4cad-863a-aeaf05af1f34%40googlegroups.com.

For more options, visit https://groups.google.com/d/optout.

Spriya

unread,
Nov 26, 2014, 2:26:34 PM11/26/14
to puppet...@googlegroups.com
Hi, 

I tried that also whether the fact is returing nil or by writing into separate facts

Here is the code:

Facter.add("java_foundversion#{java_count}_foundversion") do
 setcode do
    java_version[1]
end
end
#end
#end
#end
#end
Facter.add("java_foundversion#{java_count}_path") do
 setcode do
   java_path
end
end
end
end

My facts

java_foundversion1_foundversion => 1.7.0_65
java_foundversion1_path => /usr/lib/jvm/java-1.7.0-openjdk-1.7.0.65.x86_64/jre/bin/java
java_foundversion2_foundversion => 1.6.0_32
java_foundversion2_path => /usr/lib/jvm/java-1.6.0-openjdk-1.6.0.0.x86_64/jre/bin/java
java_foundversion3_foundversion => 1.6.0_43
java_foundversion3_path => /opt/oracle/agent12c/core/12.1.0.4.0/jdk/bin/java


But when i am concatenating the java_path is not returning.  Let me know your thoughts
Reply all
Reply to author
Forward
0 new messages