我正试图使用Ansible安装RVM,以便在远程(RedHat 6.x)系统上安装Ruby的更新版本。我尝试了两个独立的Ansible RVM剧本(RVM/rvm1-Ansible和newmen/Ansible RVM),但它们都表现出相同的行为:它们都达到了剧本指示RVM安装Ruby的步骤,然后暂停,直到我取消该过程:
TASK: [ansible-rvm | installing Ruby as root]
*********************************
<HOST.DOMAIN.xyz>
<HOST.DOMAIN.xyz>
<HOST.DOMAIN.xyz> IdentityFile=/Users/USER/.ssh/private-key-file ConnectTimeout=10 PasswordAuthentication=no KbdInteractiveAuthentication=no ControlPath=/Users/USER/.ansible/cp/ansible-ssh-%h-%p-%r PreferredAuthentications=gssapi-with-mic,gssapi-keyex,hostbased,publickey ControlMaster=auto ControlPersist=60s
<HOST.DOMAIN.xyz>
<HOST.DOMAIN.xyz> IdentityFile=/Users/USER/.ssh/private-key-file ConnectTimeout=10 'sudo -k && sudo -H -S -p "[sudo via ansible, key=KEY] password: " -u root /bin/sh -c '"'"'echo SUDO-SUCCESS-KEY; LANG=en_US.UTF-8 LC_CTYPE=en_US.UTF-8 /usr/bin/python /home/USER/.ansible/tmp/ansible-tmp-dir/command; rm -rf /home/USER/.ansible/tmp/ansible-tmp-dir/ >/dev/null 2>&1'"'"'' PasswordAuthentication=no KbdInteractiveAuthentication=no ControlPath=/Users/USER/.ansible/cp/ansible-ssh-%h-%p-%r PreferredAuthentications=gssapi-with-mic,gssapi-keyex,hostbased,publickey ControlMaster=auto ControlPersist=60s
^CERROR: interrupted
原因似乎是RVM要求提供某种登录信息。当我SSH到有问题的主机手动运行RVM时,我会得到一个提示Username:
:
$ rvm install ruby-2.2.2
Searching for binary rubies, this might take some time.
No binary rubies available for: redhat/6/x86_64/ruby-2.2.2.
Continuing with compilation. Please read 'rvm help mount' to get more information on binary rubies.
Checking requirements for redhat.
Enabling optional repository
Username: ^C
User interrupted process.
无论rvm
命令是否在sudo
下运行,都会发生上述情况。
我找不到任何关于RVM请求什么登录/用户名的文档,也找不到关于我可以应用以禁用交互的标志或配置的任何说明;事实上,我还没有找到任何与RVM结合使用的登录提示。以前有人遇到过这个问题吗?
原因是rvm正在尝试安装系统需求,这需要输入sudo密码。
我已经在rvm1的分叉中修复了这个问题,在这个提交中
在Ubuntu中对我有用。
---
- name: Configure servers with ruby support for single user
hosts: newservers
become: yes
roles:
- { role: rvm_io.ruby,
tags: ruby,
rvm1_rubies: [2.3.3],
rvm1_user: 'sudouser',
rvm1_install_flags: '--auto-dotfiles --user-install',
rvm1_install_path: '/home/{{ ansible_user }}/.rvm',
}
使用sudo用户启动任务:
ansible-playbook -i hosts.ini ruby_script.yml --user sudouser --ask-sudo-pass