我正在尝试在基于 centos 的 vagrant box 上安装带有 ansible 的 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
答案1
RVM 和 Ruby 安装手册
这是一个幂等剧本,它将安装 RVM、特定版本的 Ruby(使用 var 设置版本ruby_version
)并将该版本的 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 }}"
答案2
这对我有用(Ubuntu):
tasks:
- name: Install RVM
shell: "curl -sSL https://get.rvm.io | bash"
使用常规(非 root)用户。
答案3
目前,我认为推荐的方式是RVM 的作用。该项目的 README 中有说明。
答案4
我还尝试使用 Ansible 安装 RVM。不幸的是,RVM 无法与非交互式 shell 很好地配合使用,因为它是一个 shell 脚本函数。我最终安装了 rbenv(https://github.com/sstephenson/rbenv)。
以下是我的要点: