Forge Home

rvm

A puppet module for installing and using RVM (Ruby Version Manager)

7,296 downloads

743 latest version

4.7 quality score

We run a couple of automated
scans to help you access a
module's quality. Each module is
given a score based on how well
the author has formatted their
code and documentation and
modules are also checked for
malware using VirusTotal.

Please note, the information below
is for guidance only and neither of
these methods should be considered
an endorsement by Puppet.

Version information

  • 3.0.0 (latest)
  • 2.0.0
released Jan 9th 2024
This version is compatible with:
  • Puppet Enterprise 2023.2.x, 2023.1.x, 2023.0.x, 2021.7.x, 2021.6.x, 2021.5.x, 2021.4.x, 2021.3.x, 2021.2.x, 2021.1.x, 2021.0.x
  • Puppet >= 7.0.0 < 8.0.0
  • , , , , , ,

Start using this module

  • r10k or Code Manager
  • Bolt
  • Manual installation
  • Direct download

Add this module to your Puppetfile:

mod 'puppet-rvm', '3.0.0'
Learn more about managing modules with a Puppetfile

Add this module to your Bolt project:

bolt module add puppet-rvm
Learn more about using this module with an existing project

Manually install this module globally with Puppet module tool:

puppet module install puppet-rvm --version 3.0.0

Direct download is not typically how you would use a Puppet module to manage your infrastructure, but you may want to download the module in order to inspect the code.

Download

Documentation

puppet/rvm — version 3.0.0 Jan 9th 2024

Puppet Module for Ruby Version Manager (RVM)

This module handles installing system RVM (also known as multi-user installation as root) and using it to install rubies and gems. Support for installing and configuring passenger is also included.

We are actively using this module. It works well, but does have some issues you should be aware of. Due to the way puppet works, certain resources (rvm_sytem_ruby, rvm_gem and rvm_gemset) may generate errors until RVM is installed. You may want to use run stages to install RVM before the rest of your configuration runs. However, if you run puppet using the --noop parameter, you may see Could not find a default provider errors. See the Troubleshooting section for more information.

Please read the troubleshooting section below before opening an issue.

Add Puppet Module

Before you begin, you must add the RVM module to your Puppet installation. This can be done with:

$ puppet module install puppet/rvm

You may now continue configuring RVM resources.

Install RVM with Puppet

class { 'rvm': }

This will install RVM into /usr/local/rvm.

To use RVM without sudo, users need to be added to the rvm group. This can be easily done with:

rvm::system_user { bturner: ; jdoe: ; jsmith: ; }

If GPG is installed, installing RVM requires the RVM GPG key. This module will install the key if gpg is already installed or being installed with the golja-gnupg module.

If you don't want this module to manage any signing keys, set the signing_keys parameter to []

class { 'rvm': signing_keys => [] }

Installing Ruby

You can tell RVM to install one or more Ruby versions with:

rvm_system_ruby {
  'ruby-1.9':
    ensure      => 'present',
    default_use => true,
    build_opts  => ['--binary'];
  'ruby-2.0':
    ensure      => 'present',
    default_use => false;
}

You should use the full version number. While the shorthand version may work (e.g. '1.9.2'), the provider will be unable to detect if the correct version is installed.

If rvm fails to install binary rubies you can increase curl's timeout with the rvm_max_time_flag in ~/.rvmrc with a fully qualified path to the home directory.

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

Or, to configure /etc/rvmrc you can use use Class['rvm::rvmrc]

class{ 'rvm::rvmrc':
  max_time_flag => 20,
  before  => Class['rvm'],
}

Installing JRuby from sources

JRuby has some extra requirements, java, maven and ant that you can install using puppetlabs/java, maestrodev/ant and maestrodev/maven modules.

class { 'java': } ->
class { 'ant': } ->
class { 'maven::maven': } ->
rvm_system_ruby { 'jruby-1.7.6':
  ensure      => 'present',
  default_use => false;
}

Creating Gemsets

Create a gemset with:

rvm_gemset {
  'ruby-1.9.3-p448@myproject':
    ensure  => present,
    require => Rvm_system_ruby['ruby-1.9.3-p448'];
}

Installing Gems

Install a gem with:

rvm_gem {
  'ruby-1.9.3-p448@myproject/bundler':
    ensure  => '1.0.21',
    require => Rvm_gemset['ruby-1.9.3-p448@myproject'];
}

The name of the gem should be <ruby-version>[@<gemset>]/<gemname>. For example, you can install bundler for ruby-1.9.2 using ruby-1.9.3-p448/bundler. You could install rails in your project's gemset with: ruby-1.9.3-p448@myproject/rails.

Alternatively, you can use this more verbose syntax:

rvm_gem {
  'bundler':
    name         => 'bundler',
    ruby_version => 'ruby-1.9.3-p448',
    ensure       => latest,
    require      => Rvm_system_ruby['ruby-1.9.3-p448'];
}

Creating Aliases

To create an RVM alias, you can use:

rvm_alias {
  'myproject':
    target_ruby => 'ruby-1.9.3-p448@myproject',
    ensure      => present,
    require     => Rvm_gemset['ruby-1.9.3-p448@myproject'];
}

Creating Wrappers

To create an RVM wrapper, you can use:

rvm_wrapper {
  'god':
    target_ruby => 'ruby-1.9.3-p448',
    prefix      => 'bootup',
    ensure      => present,
    require     => Rvm_system_ruby['ruby-1.9.3-p448'];
}

Installing Passenger

NOTE: You must install the puppetlabs/apache module by yourself. It is not included as a dependency to this module to avoid installing it when is not needed most times.

Install passenger using the puppetlabs/apache module, and using:

class { 'apache': }
class { 'rvm::passenger::apache':
    version            => '3.0.11',
    ruby_version       => 'ruby-1.9.3-p448',
    mininstances       => 3,
    maxinstancesperapp => 0,
    maxpoolsize        => 30,
    spawnmethod        => 'smart-lv2',
}

Using Hiera

You can configure the ruby versions to be installed and the system users from hiera

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

rvm::system_users:
  - john
  - doe

rvm::rvm_gems:
  'bundler':
    name: 'bundler'
    ruby_version: 'ruby-1.9'
    ensure: latest

Building the module

Testing is done with rspec, Beaker-rspec, Beaker)

To test and build the module

bundle install
# run specs
rake

# run Beaker system tests with vagrant vms
rake beaker
# to use other vm from the list spec/acceptance/nodesets and not destroy the vm after the tests
BEAKER_destroy=no BEAKER_set=centos-64-x64 bundle exec rake beaker

# Release the Puppet module to the Forge, doing a clean, build, tag, push, bump_commit and git push
rake module:release

Troubleshooting / FAQ

An error "Could not find a default provider for rvm_system_ruby" is displayed when running Puppet with --noop

This means that puppet cannot find the /usr/local/rvm/bin/rvm command (probably because RVM isn't installed yet). Currently, Puppet does not support making a provider suitable using another resource (late-binding). You may want to use run stages to install RVM before the rest of the configuration runs. When running in noop mode, RVM is not actually installed causing rvm_system_ruby, rvm_gem and rvm_gemset resources to generate this error. You can avoid this error by surrounding your rvm configuration in an if block:

if $rvm_installed == "true" {
    rvm_system_ruby ...
}

Do not surround include rvm in the if block, as this is used to install RVM.

NOTE: $rvm_installed is evaluated at the beginning of each puppet run. If you use this in your manifests, you will need to run puppet twice to fully configure RVM.

Some packages/libraries I don't want or need are installed (e.g. build-essential, libc6-dev, libxml2-dev).

RVM works by compiling Ruby from source. This means you must have all the libraries and binaries required to compile Ruby installed on your system, which is handled by rvm autolibs in newer versions of RVM.

It doesn't work on my operating system.

Check the rspec-system tests as described above to test in a specific OS If that doesn't work feel free to send a pull request ;)

Why didn't you just add an RVM provider for the existing package type?

The puppet package type seems like an obvious place for the RVM provider. It would be nice if the syntax for installing Ruby with RVM looked like:

# NOTE: This does not work
package {'ruby':
    provider => 'rvm',
    ensure => '1.9.2-p290';
}

While this may be possible, it becomes harder to manage multiple Ruby versions and nearly impossible to install gems for a specific Ruby version. For this reason, I decided it was best to create a completely new set of types for RVM.