FAQ
Hello all,

I am currently trying to setup a Custom Fact that will can be used to
determine the version of the Java JRE running on a machine, in order to use
it in my manifests to ensure the proper JARS are distribured based on
environment. I'm trying to use the java -version command and then capture
the JRE release (eg "1.6.0_37"). No matter what I have tried, the output is
always the full display from the Java -version command. Has anyone done
this or something similar before? Any suggestions?

Thanks for your time,
Mike

--
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+unsubscribe@googlegroups.com.
To post to this group, send email to puppet-users@googlegroups.com.
Visit this group at http://groups.google.com/group/puppet-users?hl=en.
For more options, visit https://groups.google.com/groups/opt_out.

Search Discussions

  • Craig White at Feb 21, 2013 at 10:14 pm

    On Feb 21, 2013, at 1:27 PM, Camerodity wrote:

    Hello all,

    I am currently trying to setup a Custom Fact that will can be used to determine the version of the Java JRE running on a machine, in order to use it in my manifests to ensure the proper JARS are distribured based on environment. I'm trying to use the java -version command and then capture the JRE release (eg "1.6.0_37"). No matter what I have tried, the output is always the full display from the Java -version command. Has anyone done this or something similar before? Any suggestions?
    ----
    don't know about the java command but I suspect some variation of this will do it. (%x[ ] captures the output of command(s) executed within the square brackets)

    Facter.add("ruby_version") do
    setcode do
    ruby_version = "unknown"
    rubypath = %x[facter rubysitedir]
    ruby_version = %x[ruby -v | cut -f2 -d ' ']
    ruby_version
    end
    end

    Craig

    --
    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+unsubscribe@googlegroups.com.
    To post to this group, send email to puppet-users@googlegroups.com.
    Visit this group at http://groups.google.com/group/puppet-users?hl=en.
    For more options, visit https://groups.google.com/groups/opt_out.
  • Dan White at Feb 21, 2013 at 10:55 pm
    java -version 2>&1 | head -n 1 | cut -f2 -d'"'

    Apparently, the output goes to stderr !


    “Sometimes I think the surest sign that intelligent life exists elsewhere in the universe is that none of it has tried to contact us.”
    Bill Waterson (Calvin & Hobbes)

    ----- Original Message -----
    From: "Craig White" <craig.white@ttiltd.com>
    To: puppet-users@googlegroups.com
    Sent: Thursday, February 21, 2013 5:14:14 PM
    Subject: Re: [Puppet Users] Using Facter to find the Java version running on the machine

    On Feb 21, 2013, at 1:27 PM, Camerodity wrote:

    Hello all,

    I am currently trying to setup a Custom Fact that will can be used to determine the version of the Java JRE running on a machine, in order to use it in my manifests to ensure the proper JARS are distribured based on environment. I'm trying to use the java -version command and then capture the JRE release (eg "1.6.0_37"). No matter what I have tried, the output is always the full display from the Java -version command. Has anyone done this or something similar before? Any suggestions?
    ----
    don't know about the java command but I suspect some variation of this will do it. (%x[ ] captures the output of command(s) executed within the square brackets)

    Facter.add("ruby_version") do
    setcode do
    ruby_version = "unknown"
    rubypath = %x[facter rubysitedir]
    ruby_version = %x[ruby -v | cut -f2 -d ' ']
    ruby_version
    end
    end

    Craig

    --
    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+unsubscribe@googlegroups.com.
    To post to this group, send email to puppet-users@googlegroups.com.
    Visit this group at http://groups.google.com/group/puppet-users?hl=en.
    For more options, visit https://groups.google.com/groups/opt_out.


    --
    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+unsubscribe@googlegroups.com.
    To post to this group, send email to puppet-users@googlegroups.com.
    Visit this group at http://groups.google.com/group/puppet-users?hl=en.
    For more options, visit https://groups.google.com/groups/opt_out.
  • Steven Nemetz at Feb 21, 2013 at 11:06 pm
    This is the fact that I use Facter.add("java_version") do
    setcode do
    `/usr/bin/java -version 2>&1`.split("\n")[0].split('"')[1]
    end
    end

    Steven Date: Thu, 21 Feb 2013 22:50:24 +0000
    From: ygor@comcast.net
    To: puppet-users@googlegroups.com
    Subject: Re: [Puppet Users] Using Facter to find the Java version running on the machine

    java -version 2>&1 | head -n 1 | cut -f2 -d'"'

    Apparently, the output goes to stderr !

    “Sometimes I think the surest sign that intelligent life exists elsewhere in the universe is that none of it has tried to contact us.”
    Bill Waterson (Calvin & Hobbes)

    From: "Craig White" <craig.white@ttiltd.com>
    To: puppet-users@googlegroups.com
    Sent: Thursday, February 21, 2013 5:14:14 PM
    Subject: Re: [Puppet Users] Using Facter to find the Java version running on the machine

    On Feb 21, 2013, at 1:27 PM, Camerodity wrote:

    Hello all,

    I am currently trying to setup a Custom Fact that will can be used to determine the version of the Java JRE running on a machine, in order to use it in my manifests to ensure the proper JARS are distribured based on environment. I'm trying to use the java -version command and then capture the JRE release (eg "1.6.0_37"). No matter what I have tried, the output is always the full display from the Java -version command. Has anyone done this or something similar before? Any suggestions?
    ----
    don't know about the java command but I suspect some variation of this will do it. (%x[ ] captures the output of command(s) executed within the square brackets)

    Facter.add("ruby_version") do
    setcode do
    ruby_version = "unknown"
    rubypath = %x[facter rubysitedir]
    ruby_version = %x[ruby -v | cut -f2 -d ' ']
    ruby_version
    end
    end

    Craig

    --
    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+unsubscribe@googlegroups.com.
    To post to this group, send email to puppet-users@googlegroups.com.
    Visit this group at http://groups.google.com/group/puppet-users?hl=en.
    For more options, visit https://groups.google.com/groups/opt_out.






    --

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

    To post to this group, send email to puppet-users@googlegroups.com.

    Visit this group at http://groups.google.com/group/puppet-users?hl=en.

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






    --
    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+unsubscribe@googlegroups.com.
    To post to this group, send email to puppet-users@googlegroups.com.
    Visit this group at http://groups.google.com/group/puppet-users?hl=en.
    For more options, visit https://groups.google.com/groups/opt_out.
  • Camerodity at Feb 25, 2013 at 1:56 pm
    Steven,

    Thanks!! Your example really helped me and I now have the desired custom
    fact
    On Thursday, February 21, 2013 6:06:57 PM UTC-5, Steven wrote:

    This is the fact that I use

    Facter.add("java_version") do
    setcode do
    `/usr/bin/java -version 2>&1`.split("\n")[0].split('"')[1]
    end
    end


    Steven

    ------------------------------
    Date: Thu, 21 Feb 2013 22:50:24 +0000
    From: yg...@comcast.net <javascript:>
    To: puppet...@googlegroups.com <javascript:>
    Subject: Re: [Puppet Users] Using Facter to find the Java version running
    on the machine

    java -version 2>&1 | head -n 1 | cut -f2 -d'"'

    Apparently, the output goes to stderr !

    “Sometimes I think the surest sign that intelligent life exists elsewhere
    in the universe is that none of it has tried to contact us.”
    Bill Waterson (Calvin & Hobbes)

    ------------------------------
    *From: *"Craig White" <craig...@ttiltd.com <javascript:>>
    *To: *puppet...@googlegroups.com <javascript:>
    *Sent: *Thursday, February 21, 2013 5:14:14 PM
    *Subject: *Re: [Puppet Users] Using Facter to find the Java version
    running on the machine

    On Feb 21, 2013, at 1:27 PM, Camerodity wrote:

    Hello all,

    I am currently trying to setup a Custom Fact that will can be used to
    determine the version of the Java JRE running on a machine, in order to use
    it in my manifests to ensure the proper JARS are distribured based on
    environment. I'm trying to use the java -version command and then capture
    the JRE release (eg "1.6.0_37"). No matter what I have tried, the output is
    always the full display from the Java -version command. Has anyone done
    this or something similar before? Any suggestions?
    ----
    don't know about the java command but I suspect some variation of this
    will do it. (%x[ ] captures the output of command(s) executed within the
    square brackets)

    Facter.add("ruby_version") do
    setcode do
    ruby_version = "unknown"
    rubypath = %x[facter rubysitedir]
    ruby_version = %x[ruby -v | cut -f2 -d ' ']
    ruby_version
    end
    end

    Craig

    --
    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 <javascript:>.
    To post to this group, send email to puppet...@googlegroups.com<javascript:>
    .
    Visit this group at http://groups.google.com/group/puppet-users?hl=en.
    For more options, visit https://groups.google.com/groups/opt_out.



    --
    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 <javascript:>.
    To post to this group, send email to puppet...@googlegroups.com<javascript:>
    .
    Visit this group at http://groups.google.com/group/puppet-users?hl=en.
    For more options, visit https://groups.google.com/groups/opt_out.

    --
    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+unsubscribe@googlegroups.com.
    To post to this group, send email to puppet-users@googlegroups.com.
    Visit this group at http://groups.google.com/group/puppet-users?hl=en.
    For more options, visit https://groups.google.com/groups/opt_out.
  • Camerodity at Feb 25, 2013 at 1:50 pm
    Great! Thank you so much, I used your example and got the desired output. I
    really appreciate your time.

    Mike
    On Thursday, February 21, 2013 5:50:24 PM UTC-5, Ygor wrote:

    java -version 2>&1 | head -n 1 | cut -f2 -d'"'

    Apparently, the output goes to stderr !

    “Sometimes I think the surest sign that intelligent life exists elsewhere
    in the universe is that none of it has tried to contact us.”
    Bill Waterson (Calvin & Hobbes)

    ------------------------------
    *From: *"Craig White" <craig...@ttiltd.com <javascript:>>
    *To: *puppet...@googlegroups.com <javascript:>
    *Sent: *Thursday, February 21, 2013 5:14:14 PM
    *Subject: *Re: [Puppet Users] Using Facter to find the Java version
    running on the machine

    On Feb 21, 2013, at 1:27 PM, Camerodity wrote:

    Hello all,

    I am currently trying to setup a Custom Fact that will can be used to
    determine the version of the Java JRE running on a machine, in order to use
    it in my manifests to ensure the proper JARS are distribured based on
    environment. I'm trying to use the java -version command and then capture
    the JRE release (eg "1.6.0_37"). No matter what I have tried, the output is
    always the full display from the Java -version command. Has anyone done
    this or something similar before? Any suggestions?
    ----
    don't know about the java command but I suspect some variation of this
    will do it. (%x[ ] captures the output of command(s) executed within the
    square brackets)

    Facter.add("ruby_version") do
    setcode do
    ruby_version = "unknown"
    rubypath = %x[facter rubysitedir]
    ruby_version = %x[ruby -v | cut -f2 -d ' ']
    ruby_version
    end
    end

    Craig

    --
    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 <javascript:>.
    To post to this group, send email to puppet...@googlegroups.com<javascript:>
    .
    Visit this group at http://groups.google.com/group/puppet-users?hl=en.
    For more options, visit https://groups.google.com/groups/opt_out.

    --
    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+unsubscribe@googlegroups.com.
    To post to this group, send email to puppet-users@googlegroups.com.
    Visit this group at http://groups.google.com/group/puppet-users?hl=en.
    For more options, visit https://groups.google.com/groups/opt_out.
  • Kyle Sexton at Feb 21, 2013 at 10:33 pm

    Camerodity writes:

    Hello all,

    I am currently trying to setup a Custom Fact that will can be used to determine the version of the
    Java JRE running on a machine, in order to use it in my manifests to ensure the proper JARS are
    distribured based on environment. I'm trying to use the java -version command and then capture the
    JRE release (eg "1.6.0_37"). No matter what I have tried, the output is always the full display
    from the Java -version command. Has anyone done this or something similar before? Any suggestions?
    Hard to know for sure without seeing any code. Have you checked that
    it's going to stdout?

    java -version 1> 1.txt
    java -version 2> 2.txt

    Also, perhaps looking at the package (rpm, deb, etc..) installed would be more
    effective?

    --
    Kyle Sexton

    --
    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+unsubscribe@googlegroups.com.
    To post to this group, send email to puppet-users@googlegroups.com.
    Visit this group at http://groups.google.com/group/puppet-users?hl=en.
    For more options, visit https://groups.google.com/groups/opt_out.

Related Discussions

Discussion Navigation
viewthread | post
Discussion Overview
grouppuppet-users @
categoriespuppet
postedFeb 21, '13 at 9:33p
activeFeb 25, '13 at 1:56p
posts7
users5
websitepuppetlabs.com

People

Translate

site design / logo © 2021 Grokbase