Ask Your Question
1

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

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

UnitedMarsupials gravatar image

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

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
0

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

UnitedMarsupials gravatar image

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

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"
    end 
end

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
1

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

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

Comments

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 -0500 )edit

Well, I'm stuck creating my own provider and have asked a [separate question](https://ask.puppet.com/question/27071/how-to-access-the-value-of-new-parameter-inside-a-custom-package-provider/) about that. Would you share your thoughts?

UnitedMarsupials gravatar imageUnitedMarsupials ( 2016-07-07 17:22:39 -0500 )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

Stats

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

Seen: 101 times

Last updated: Jul 07 '16