安装RVM

我试图在一个基于centos的stream浪盒子上安装rvm。

我正在运行的命令是:

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

它非常有效,但Ansible认为它失败了。

Ansible的输出是:

 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 

这对我有用(Ubuntu):

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

使用常规(非root)用户。

RVM和Ruby安装手册

这是一个幂等手册,将安装RVM,一个特定版本的Ruby(使用ruby_version var设置版本),并将该版本的Ruby设置为默认值:

 --- - 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: append rvm path to environment lineinfile: dest=/etc/environment state=present backrefs=yes regexp='PATH=(["]*)((?!.*?{{rvm_path}}).*?)(["]*)$' line="PATH=\1\2:{{rvm_path}}\3" - 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 }}" 

以@ dynex的答案为基础,通过检查一个通常会创build的文件夹,这是一种更琢磨一下的方法。

 - 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 

这些天,我相信推荐的方式是RVM的作用 。 该项目的自述文件中有说明。

我也试着用Ansible安装RVM。 不幸的是,RVM不能很好地与非交互式shell进行交互,因为它是一个shell脚本函数。 我结束了安装rbenv( https://github.com/sstephenson/rbenv )。

这是我的要点:

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

这可能是因为脚本的响应代码是非零的?

“rc”:1

因为rvm对于非交互式shell不太好,如果你仍然想使用rvm,你必须编写你自己的脚本来调用rvm,但是用bash -l (一个loginshell)开始:

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

其中install-ruby-1.9.3.sh包含类似的东西

 #!/bin/bash -l rvm install 1.9.3 

尽量保持这样的脚本小,并只集中于一个任务(如果有一个非0的退出值,您可以接受,另外还要为主命令处理$? )。 对于第二个ruby使用封装第二个命令的第二个脚本。