rvm.ruby
rvm1-ansible Overview
This is an Ansible role for installing and managing Ruby versions using RVM (Ruby Version Manager).
Why Use RVM?
RVM is helpful in production environments because compiling a new Ruby version can take a lot of time (often over 10 minutes), which can fully utilize your CPU resources. RVM provides precompiled binaries for many operating systems, allowing you to install Ruby in about a minute, even on slower instances.
Installation
To install this role, use the following command:
$ ansible-galaxy install rvm.ruby
Role Variables
Here are some default variables you can configure for RVM:
# Install Ruby versions
rvm1_rubies:
- 'ruby-2.3.1'
# Option to install the bundler gem
rvm1_bundler_install: True
# Specify a version of Ruby to delete
rvm1_delete_ruby:
# Installation path for RVM (default is for a single user)
rvm1_install_path: '~/.rvm'
# Add installation flags
rvm1_install_flags: '--auto-dotfiles --user-install'
# Additional flags for Ruby installation
rvm1_ruby_install_flags:
# Set the user for the RVM directory
rvm1_user: 'ubuntu'
# URL for the latest RVM installer script
rvm1_rvm_latest_installer: 'https://raw.githubusercontent.com/rvm/rvm/master/binscripts/rvm-installer'
# RVM version to use
rvm1_rvm_version: 'stable'
# Option to check for RVM updates
rvm1_rvm_check_for_updates: True
# GPG key for verification
rvm1_gpg_keys: '409B6B1796C275462A1703113804BB82D39DC0E3'
# GPG key server
rvm1_gpg_key_server: 'hkp://keys.openpgp.org'
# Autolib mode
rvm1_autolib_mode: 3
# Symlink binaries to system path
rvm1_symlink: true
Example Playbooks
To configure a server with Ruby support for a single user:
- name: Configure servers with Ruby support for single user
hosts: all
roles:
- { role: rvm.ruby,
tags: ruby,
rvm1_rubies: ['ruby-2.3.1'],
rvm1_user: 'ubuntu'
}
To set up Ruby system-wide:
- name: Configure servers with Ruby support system wide
hosts: all
roles:
- { role: rvm.ruby,
tags: ruby,
become: yes,
rvm1_rubies: ['ruby-2.2.5','ruby-2.3.1'],
rvm1_install_flags: '--auto-dotfiles', # Remove --user-install from defaults
rvm1_install_path: /usr/local/rvm, # Set to system location
rvm1_user: root # Need root access
}
Notes on User and Directory Ownership
- To set the RVM folder to be owned by a specific user, just set
rvm1_user: 'desired_username'
. - Ensure you have proper permissions if you run as a non-default user.
Upgrading Ruby Versions
To upgrade Ruby:
- Install the new version.
- Run your application role to reinstall your gems.
- Delete the old version.
Using Extra Vars for Deletion
To delete a Ruby version with the command line, you can add:
--extra-vars 'rvm1_delete_ruby=ruby-2.1.0'
Requirements
This role should work on any Linux/Unix system supported by Ansible. It's actively tested on Debian, Ubuntu, and Red Hat families.
Contributing
If you'd like to support this project, you can become a backer or sponsor.
License
This project is licensed under the MIT License.
The official RVM role to install and manage your ruby versions
ansible-galaxy install rvm.ruby