Take the 2-minute tour ×
Server Fault is a question and answer site for system and network administrators. It's 100% free, no registration required.

I am attempting to install rvm with ansible on a centos-based vagrant box.

The command I am running is:

vars:
  user: "foo"

- name: install rvm
  action: command sudo -u $user bash /home/$user/rvm-install.sh stable creates=$home/.rvm

It pretty much works BUT Ansible thinks it has failed.

Ansible output is:

failed: [127.0.0.1] => {"changed": true, "cmd": ["sudo", "-u", "foo", "bash", "/home/foo/rvm-install.sh", "stable"], "delta": "0:00:21.102322", "end": "2012-10-09 12:33:19.917874", "rc": 1, "start": "2012-10-09 12:32:58.815552"}
stderr: % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                 Dload  Upload   Total   Spent    Left  Speed
100 1081k  100 1081k    0     0  54170      0  0:00:20  0:00:20 --:--:-- 89264
stdout: Downloading RVM from wayneeseguin branch stable

Installing RVM to /home/foo/.rvm/
    RVM PATH line found in /home/foo/.bashrc /home/foo/.zshenv.
    RVM sourcing line found in /home/foo/.bash_profile /home/foo/.zprofile.

# RVM:  Shell scripts enabling management of multiple ruby environments.
# RTFM: https://rvm.io/
# HELP: http://webchat.freenode.net/?channels=rvm (#rvm on irc.freenode.net)
# Cheatsheet: http://cheat.errtheblog.com/s/rvm/
# Screencast: http://screencasts.org/episodes/how-to-use-rvm

# In case of any issues read output of 'rvm requirements' and/or 'rvm notes'

Installation of RVM in /home/foo/.rvm/ is almost complete:

  * To start using RVM you need to run `source /home/foo/.rvm/scripts/rvm`
    in all your open shell windows, in rare cases you need to reopen all shell windows.

# root,
#
#   Thank you for using RVM!
#   I sincerely hope that RVM helps to make your life easier and more enjoyable!!!
#
# ~Wayne
share|improve this question

7 Answers 7

This worked for me (Ubuntu):

    tasks:
      - name: Install RVM
        shell: "curl -sSL https://get.rvm.io | bash"

Using a regular (non-root) user.

share|improve this answer
    
that gist and blog post don't use this and don't use RVM. It says that's intended for a later post. –  mahemoff Jan 9 '14 at 0:34
2  
I'm sorry, you'r right - I changed the blog not to use RVM and wanted to do a separate write up for RVM. When I was testing with RVM, the above worked, but not "system-wide" for which you need "shell: "curl -sSL get.rvm.io | sudo bash". Sorry for the confusion and I will remove the link to the gist. –  dynex Jan 9 '14 at 19:00

These days, I believe the recommended way is with RVM's ansible role. There are instructions in that project's README.

share|improve this answer

I also tried installing RVM with Ansible. Unfortunately RVM doesn't play nicely with non-interactive shells, because it is a shell script function. I ended up installing rbenv instead (https://github.com/sstephenson/rbenv).

Here is my gist:

https://gist.github.com/brendan-skyrkt/7699067

share|improve this answer
    
Yeah took me a while, but got it to work (non-global, single user). Here's the gist and the blog: gist.github.com/ihassin/7968406. Blog at ihassin.wordpress.com/2013/12/15/… –  dynex Dec 16 '13 at 0:34

Building on @dynex's answer, here's a way to do it a bit more idempotently, by checking for a folder it would normally create.

- stat: path=/etc/profile.d/rvm.sh
  register: rvm_folder

- name: install rvm
  shell: "curl -sSL https://get.rvm.io | bash"
  when: rvm_folder.stat.isdir is not defined
share|improve this answer
1  
Nice :) Ansible is full of hidden gems. Pun intended... –  dynex Jan 13 '14 at 0:57

RVM & Ruby Installation Playbook

Here's an idempotent playbook that will install RVM, a specific version of Ruby (set the version with the ruby_version var) and set that version of Ruby to be the default:

---

- hosts: all
  sudo: yes
  vars:
    ruby_version: "2.1.3"
    rvm_path: "/usr/local/rvm/gems/ruby-{{ ruby_version }}/bin:/usr/local/rvm/gems/ruby-{{ ruby_version }}@global/bin:/usr/local/rvm/rubies/ruby-{{ ruby_version }}/bin:/usr/local/rvm/bin"

  tasks:
  - name: ensure necessary packages are installed
    yum:
      name: "{{ item }}"
      state: present
    with_items:
      - curl
      - gnupg2

  - name: ensure that GPG key for RVM is installed
    command: gpg2 --keyserver hkp://keys.gnupg.net --recv-keys D39DC0E3
    args:
      creates: /root/.gnupg/secring.gpg

  - name: ensure that RVM is installed
    shell: curl -L get.rvm.io | bash -s stable
    args:
      creates: /usr/local/rvm

  - name: ensure that ruby is installed
    command: "rvm install {{ ruby_version }}"
    args:
      creates: "/usr/local/rvm/gems/ruby-{{ ruby_version }}"
    environment:
      PATH: "{{ rvm_path }}:{{ ansible_env.PATH }}"

  - name: set default version of ruby with rvm
    command: "rvm alias create default ruby-{{ ruby_version }}"
    args:
      creates: /usr/local/rvm/config/alias
    environment:
      PATH: "{{ rvm_path }}:{{ ansible_env.PATH }}"
share|improve this answer

It is possibly because the response code from the script is non-zero?

"rc": 1

share|improve this answer

Because rvm does not play nice with non interactive shells if you still want to use rvm with ansible, you have to write your own scripts that call rvm but start with bash -l (a login shell):

- name: install ruby-1.9.3
    script: scripts/install-ruby-1.9.3.sh

Where install-ruby-1.9.3.sh contains something like

#!/bin/bash -l
rvm install 1.9.3

Try to keep such scripts small and focused to one task only (plus handling $? for the main command if there is an exit value other than 0 which you want to accept). For a second ruby use a second script that encapsulates the second command.

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.