Installing RVM and multiple ruby versions with Puppet

rvm_logoWith the latest version of the Puppet RVM module it is even easier to install multiple versions of Ruby


# install rubies from binaries
Rvm_system_ruby {
  ensure     => present,
  build_opts => ['--binary'],
}

# ensure rvm doesn't timeout finding binary rubies
# the umask line is the default content when installing rvm if file does not exist
file { '/etc/rvmrc':
  content => 'umask u=rwx,g=rwx,o=rx
                     export rvm_max_time_flag=20',
  mode    => '0664',
  before  => Class['rvm'],
}

class { 'rvm': }
rvm::system_user { 'vagrant': }
rvm_system_ruby {
  'ruby-1.9.3':
    default_use => true;
  'ruby-2.0.0':;
  'jruby':;
}

Hiera can also be used to define what rubies to install, making the Puppet code even less verbose

...
class { 'rvm': }
# rvm::system_user no longer needed
# rvm_system_ruby no longer needed

The equivalent hiera yaml configuration to the previous example

rvm::system_rubies:
  '1.9':
    default_use: true
  '2.0': {}
  'jruby-1.7': {}

rvm::system_users:
  - vagrant

9 thoughts on “Installing RVM and multiple ruby versions with Puppet

  1. If you want to speed up the ruby version installation, I manage to spare a few minutes by using an exec to run a rvm mount command. Is this possible with the rvm puppet module ?

    Did you investigate if it’s possible to make a package (debian, yum) of rvm and their rubies (with fpm or omnibus) ?
    I trying to stop depending on the whole internet to provision a machine ;)

    http://mestachs.wordpress.com/2013/10/02/puppet-spare-3-minutes-per-provisionning-for-your-ruby-installation/

    • mount is not available in the module yet, it would be interesting to add, although you still need to put the tarballs somewhere. I use a shared folder in my host for vagrant boxes to avoid redownloading everything.

      About packaging I try to avoid repackaging if the project itself doesn’t support it, because in next versions it will break for sure

  2. Hello thanks for the post, I put exactly the same code that you posted.. on my puppet recipe, the only change that I did.. was set the default_use => true to jruby…….. but when I run the provision, I got this error: Could not autoload rvm_system_ruby:

    Could not autoload /tmp/vagrant-puppet-1/modules-0/rvm/lib/puppet/provider/rvm_system_ruby/rvm_system_ruby.rb: undefined method `has_command’ for Puppet::Type::Rvm_system_ruby::ProviderRvm:Class at

    could you help me, I am using the precise64 box, (ubuntu 12.04 64bits)

      • I’m using puppet v 2.7.19, I don’t know why this problem happen, y went to the path, until rvm_system_ruby.rb and the method ‘has_command’ exists, and if I go to the init.pp (rvm module), on line 23 : create_resources(‘rvm_system_ruby’, $system_rubies, {‘ensure’ => present}), here is where the problem apparently ocurr,

        (sorry for my bad english), but if you know something about, I will really appreciate.

  3. Hi,

    i’m also getting this error:

    Could not autoload rvm_system_ruby: Could not autoload /tmp/vagrant-puppet-1/modules-0/rvm/lib/puppet/provider/rvm_system_ruby/rvm_system_ruby.rb: undefined method `has_command’ for Puppet::Type::Rvm_system_ruby::ProviderRvm:Class at /tmp/vagrant-puppet-1/modules-0/rvm/manifests/init.pp:25 on node web

    using Puppet 3.

    Can you help me please ?

    Regards,
    Mihai

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s