Ask Your Question

How to install gems for non-default Ruby with Puppet?

asked 2016-07-06 08:38:53 -0600

UnitedMarsupials gravatar image

updated 2016-07-06 08:40:12 -0600

The ruby included with RedHat/CentOS-6 is of version 1.8.7, which is too old for many applications. Though simply updating it with a custom-built RPM is possible, my colleagues shy away from the idea and wish to use the rh-ruby22 packages available from the SCL-repo.

That installs ruby-2.2, which is great, but under /opt/rh/rh-ruby22. I now need to install several gems and would like to, obviously, use Puppet:

package {'example':
  ensure   => '0.25',
  provider => 'gem'

Unfortunately, the gem-provider invokes /usr/bin/gem instead of /opt/rh/rh-ruby22/root/usr/bin/gem that needs to be invoked. Is there any other way? Thanks!

Do I have to implement my own package-provider, perhaps?

edit retag flag offensive close merge delete

2 Answers

Sort by ยป oldest newest most voted

answered 2016-07-07 20:37:48 -0600

UnitedMarsupials gravatar image

updated 2016-07-07 20:38:47 -0600

Ok, the simple -- if not necessarily the most beautiful -- solution is to implement a custom gem2-provider as a descendant of gem. Below is the entire contents of the file, saved under modules/FOO/lib/puppet/provider/package/gem2.rb

require 'puppet/provider/package'

Puppet::Type.type(:package).provide :gem2, :parent => :gem, :source => :gem do
    desc "Ruby Gem support using gem2-executable if available"

    # Where Ruby-2.x is already the main ruby, do nothing special. On
    # other systems gem2-wrapper will be created by other means
    # and we'll use it here:
    if which("gem2")
        commands :gemcmd => "gem2"

A more comprehensive provider, where the command (gem, gem2, whatever) can be specified in the manifest, can be implemented too, but only as a complete rewrite of gem, rather than descending from it.

edit flag offensive delete link more

answered 2016-07-06 18:52:08 -0600

lupin gravatar image

As stated by Alex you might now want to do this but still if you really wanted to, You can can either; patch gem provider that comes with your Puppet install, seems like you only need to modify the

'commands :gemcmd => "gem"'

into something pointing to RH gem.

Cleaner way is to create your own provider, probably custom_gem or something.

edit flag offensive delete link more


Yes, I'm working on that now -- trying to inherit from the gem-provider class... Not there yet, though...

UnitedMarsupials gravatar imageUnitedMarsupials ( 2016-07-06 19:29:30 -0600 )edit

Well, I'm stuck creating my own provider and have asked a [separate question]( about that. Would you share your thoughts?

UnitedMarsupials gravatar imageUnitedMarsupials ( 2016-07-07 17:22:39 -0600 )edit

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account.

Add Answer

Question Tools


Asked: 2016-07-06 08:38:53 -0600

Seen: 423 times

Last updated: Jul 07 '16