我正在尝试使用Ansible执行此命令:
- name: install node v5.5.0
sudo: yes
shell: nvm ls-remote
environment:
http_proxy: http://17.99.193.229:3128
https_proxy: http://17.99.193.229:3128
我尝试了shell和命令。
使用命令时:我收到此错误:
"[Errno 2] No such file or directory", "rc": 2"
使用shell时:我收到此错误:
"fatal: [gocdagent-dev-01.rno.apple.com]: FAILED! => {"changed": true, "cmd": "nvm ls-remote", "delta": "0:00:00.016365", "end": "2016-05-16 18:26:07.259729", "failed": true, "rc": 127, "start": "2016-05-16 18:26:07.243364", "stderr": "/bin/sh: nvm: command not found", "stdout": "", "stdout_lines": [], "warnings": []}"
我可以直接在系统上执行nvm
命令。为什么Ansible不能运行nvm
?
答案 0 :(得分:2)
因为您在Ansible脚本中以root
(sudo:yes)运行它。确保nvm
位于root的PATH中,或者在shell命令中提供/full/path/to/nvm
。
答案 1 :(得分:1)
Nvm不是二进制文件,你必须先加载它:
- name: install node v5.5.0
shell: . <NVM_DIR>/.nvm/nvm.sh && nvm ls-remote
environment:
http_proxy: http://17.99.193.229:3128
https_proxy: http://17.99.193.229:3128