带有nvm的Ansible命令模块

时间:2016-05-16 18:32:59

标签: linux ansible nvm

我正在尝试使用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

2 个答案:

答案 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