detect python|ruby|foo-package installed

44 views
Skip to first unread message

Alexander Gray II

unread,
Apr 18, 2014, 10:09:56 PM4/18/14
to puppet...@googlegroups.com
Is there a way in puppet to detect what version of python or ruby, or for that matter, any package which is installed?

For instance:
if python_version > x:
    do something
else
    do something else

It looks liek versioncmp is what I want, but I don't know how to get the version.
Maybe do some sort of exec that gets this version?

Sorry if this a newb question,
Thanks

Jakov Sosic

unread,
Apr 19, 2014, 6:28:33 AM4/19/14
to puppet...@googlegroups.com
You could write a custom fact, that would get you version number.

One problem with that is the first puppet run, before the package is
installed, that fact would have to return something like '0', or 'nil',
so you would have to run puppet twice to get a node to a desired state.

I haven't found more intelligent approach to this problem so far :-/

Alexander Gray II

unread,
Apr 19, 2014, 11:49:42 AM4/19/14
to puppet...@googlegroups.com
Thanks Jakov!

I do have a few custom facts that I'm using, but like you said, I'd need to run puppet twice.
I wonder if I should test for the existence of a known file particular to the version of the package?
Seems a bit hacky, but it's just a thought.

Thanks,
Ale 

Alexander Gray II

unread,
Apr 19, 2014, 11:58:29 AM4/19/14
to puppet...@googlegroups.com
I just finished reading this post:
Which makes me think I may be approaching my problem the wrong way.

In other words, I *tell* puppet what version of python|ruby should be on there, and then act on it.
No need to check versions.

Nonetheless, I'm curious if it's even possible to this.

jcbollinger

unread,
Apr 19, 2014, 12:30:04 PM4/19/14
to puppet...@googlegroups.com


It's a question of defining what you're actually after.  If the question is "what version of Python (for example) is installed NOW?" then a custom fact is the right approach.  If the question is what version of Python will be installed at some future time, then you need a fortune teller instead.  Or else you need to manage that aspect of your node's configuration.

Whenever possible it is better to tell Puppet what configuration you want to achieve than to inquire.  So, if you want Python 2.7, for example, then declare that to Puppet, and rely on Puppet to make it so.  In some cases that may require some knowledge of the possibilities -- e.g. RHEL 6's official packages are pegged to Python 2.6 -- but that's knowledge you (can) have.


John

jcbollinger

unread,
Apr 19, 2014, 12:37:52 PM4/19/14
to puppet...@googlegroups.com


Again, it depends on what "this" is.  Just as you can write a custom fact to check what version of some piece of software is installed, you can write one to determine (say) the latest version of some particular package available from the currently-configured repositories.  That's the version your node would end up with under certain reasonably controllable circumstances, but it's important to separate the meaning of the fact itself -- package version relative to some random repository configuration -- from any inferences you draw from that, such as what package version will be installed at some particular point in the future.


John

Reply all
Reply to author
Forward
0 new messages