how to compare facts using variables in a text file

44 views
Skip to first unread message

Spriya

unread,
Nov 18, 2014, 8:36:59 AM11/18/14
to puppet...@googlegroups.com
Hi,

I have a requirement how to compare facts using variables which are in a txt file

For example i have a facts
java_known_weblogic_version11.7.0_72

I have txt file javaversion.txt file
1.7.0_72

I want to comapare these files java_known_weblogic_version != javaversion.txt   file?

How can i do that

Anyone please help me

Thank you

Felix Frank

unread,
Nov 19, 2014, 8:57:17 AM11/19/14
to puppet...@googlegroups.com
Hi,

so the .txt file is on the agent?

Where is the fact from?

Spriya

unread,
Nov 19, 2014, 11:36:57 AM11/19/14
to puppet...@googlegroups.com
Hi,

Yes .txt can be on agent.

The fact is already displayed on agent

Let me know

Ashish Jaiswal

unread,
Nov 19, 2014, 11:16:10 PM11/19/14
to puppet...@googlegroups.com, Spriya
Hi,

Just a quick hack.

<!-- HTML generated using hilite.me --><div style="background: #ffffff; overflow:auto;width:auto;border:solid gray;border-width:.1em .1em .1em .8em;padding:.2em .6em;"><pre style="margin: 0; line-height: 125%">     javaversion.rb
    <span style="color: #00aaaa">require</span> <span style="color: #aa5500">&#39;facter&#39;</span>

    <span style="color: #aa0000">Facter</span>.add(<span style="color: #0000aa">:is_javaversion</span>) <span style="color: #0000aa">do</span>
    setcode <span style="color: #0000aa">do</span>
            a = <span style="color: #aa0000">File</span>.readlines(<span style="color: #aa5500">&#39;javaversion.txt&#39;</span>).map { |x| x.chomp }.join
            <span style="color: #0000aa">if</span> <span style="color: #aa0000">Facter</span>.value(<span style="color: #0000aa">:java_known_weblogic_version1</span>) == a
                    <span style="color: #0000aa">true</span>
            <span style="color: #0000aa">else</span>
                    <span style="color: #0000aa">false</span>
            <span style="color: #0000aa">end</span>
    <span style="color: #0000aa">end</span>
    <span style="color: #0000aa">end</span>
</pre></div>
--

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...@googlegroups.com.

To view this discussion on the web visit https://groups.google.com/d/msgid/puppet-users/65a00b97-982c-4de7-af48-39f0839095c8%40googlegroups.com.

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






Ashish Jaiswal

unread,
Nov 19, 2014, 11:17:58 PM11/19/14
to puppet...@googlegroups.com, Spriya
Sorry,

Was trying something..

A clear snippet.

require 'facter'

Facter.add(:is_javaversion) do
setcode do
        a = File.readlines('javaversion.txt').map { |x| x.chomp }.join
        if Facter.value(:java_known_weblogic_version1) == a
                true
        else
                false
        end
end
end

Felix Frank

unread,
Nov 20, 2014, 6:07:30 AM11/20/14
to puppet...@googlegroups.com
On 11/19/2014 05:36 PM, Spriya wrote:
> Hi,
>
> Yes .txt can be on agent.
>
> The fact is already displayed on agent

Yes, but is it a custom fact you made? Is it from some module?

I get the feeling you might be over-engineering here.

What is the source of the information in the text file?

I feel that there might be a much cleaner solution than you are
designing. What is the greater problem you are solving?

Spriya

unread,
Nov 20, 2014, 9:54:26 AM11/20/14
to puppet...@googlegroups.com
Hi,

i made a custom fact, I am doing this because my manger wants an alert if the value doesnt match or changed by comparing with the external and the values we are comparing with the facts should be from a txt file not writing the values directly in the .pp file

Can you give me any suggestion?

Felix Frank

unread,
Nov 20, 2014, 11:04:43 AM11/20/14
to puppet...@googlegroups.com
On 11/20/2014 03:54 PM, Spriya wrote:
> Hi,
>
> i made a custom fact, I am doing this because my manger wants an alert
> if the value doesnt match or changed by comparing with the external and
> the values we are comparing with the facts should be from a txt file not
> writing the values directly in the .pp file
>
> Can you give me any suggestion?

In this case, I'd write a simple bash plugin for your monitoring
solution of choice, make Puppet distribute that and use monitoring to
keep track of the version match.

This script would use your fact via `facter -p`, or reimplement its
logic, so that you can do away with the fact.

HTH,
Felix

Spriya

unread,
Nov 20, 2014, 11:26:25 AM11/20/14
to puppet...@googlegroups.com
Hi,

Do you have any sample script. ?
Reply all
Reply to author
Forward
0 new messages