Rubygem not visible to puppet

231 views
Skip to first unread message

Fraser Goffin

unread,
Jan 8, 2016, 6:14:06 AM1/8/16
to Puppet Users
Puppet Version: 4.3.1
OS: Centos 7

Note: I am running MASTERLESS

I used this to install a gem :-

package { 'rubyzip':
    ensure   => present,
    provider => 'gem',
}

It installed fine, in this location : /usr/local/share/gems/gems/rubyzip-1.1.7

gem env shows that the parent folder is on the gem path :-

  - GEM PATHS:
     - /home/vagrant/.gem/ruby
     - /usr/share/gems
     - /usr/local/share/gems

However, when a Puppet manifest attempts to make use of that gem, it can't find it.

Puppet has its own location for gems, in this particular install its : /opt/puppetlabs/puppet/lib/ruby/gems/2.1.0/gems

If I change the package to include that directory as an install option, the gem is indeed installed there and Puppet can use it :-

  package { 'rubyzip':
    ensure   => present,
    provider => 'gem',
    install_options => {
            '--install-dir' => "/opt/puppetlabs/puppet/lib/ruby/gems/2.1.0"
      }
  }

However, this approach seems a bit of a hack and one that will utlimately create a maintenance overhead as/when Puppet's version of Ruby is updated, not to mention that we also run Puppet on other platforms (including Windows) which have different paths. I could handle that but it seems like there must be a better way of making this work cross platform without resorting to hard-coded paths even if that is parameterised.

Has anyone got a suggestion how to solve this one more elegantly.

Kind Regards

Fraser.

Ramin K

unread,
Jan 8, 2016, 12:55:31 PM1/8/16
to puppet...@googlegroups.com
> ultimately create a maintenance overhead as/when Puppet's version of
> Ruby is updated, not to mention that we also run Puppet on other
> platforms (including Windows) which have different paths. I could handle
> that but it seems like there must be a better way of making this work
> cross platform without resorting to hard-coded paths even if that is
> parametrized.
>
> Has anyone got a suggestion how to solve this one more elegantly?

You might create Gemfile/Gemfile.lock files that manage the versions you
expect Puppet to use.

# example code, I'm sure none of the paths and
# checks are actually correct.
# install bundler
exec { 'puppetserver install bundler':
command => 'puppetserver gem install bundler --no-ri --no-rdoc',
unless => 'puppetserver gem list | grep bundler',
}

# managed your Gemfile/Gemfile.lock as part of the repo
exec { 'puppet gems bundle install':
command => '/opt/puppetlabs/puppet/bin/bundle
/etc/puppetlabs/gems/Gemfile',
unless => 'bundle check',
}

Ramin

Josh Cooper

unread,
Jan 8, 2016, 1:32:20 PM1/8/16
to puppet...@googlegroups.com

--
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/9073677f-6cca-40b4-8949-fba8553edee9%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

I'd recommend using the `puppet_gem` package provider, which in 4.x manages gems in the AIO package, e.g.

package { 'rubyzip':
    ensure   => present,
    provider => 'puppet_gem',
}

Josh

--
Josh Cooper
Developer, Puppet Labs

Fraser Goffin

unread,
Jan 9, 2016, 12:02:32 PM1/9/16
to Puppet Users
Thanks Josh, that did the trick on both Linux and Windows.
Reply all
Reply to author
Forward
0 new messages