我试图在Ubuntu 18.04.2 LTS上使用ansible剧本脚本将npm与nvm一起安装。它正在安装中,但是在运行npm install命令时会返回错误["/bin/bash: npm: command not found"]
这是脚本
- name: Create destination dir if it does not exist
file:
mode: 0775
path: "/usr/local/nvm"
state: directory
when: "nvm_dir != ''"
- name: Install NVM
shell: "curl https://raw.githubusercontent.com/creationix/nvm/v0.33.11/install.sh | NVM_SOURCE="" NVM_DIR=/usr/local/nvm PROFILE=/root/.bashrc bash"
args:
warn: false
register: nvm_result
这是我获取代码(https://github.com/morgangraphics/ansible-role-nvm)的存储库
答案 0 :(得分:0)
默认情况下,除非已使用args / keyword在模块中明确定义了可执行文件,否则默认的shell模块将使用/bin/sh
。
似乎像/bin/bash
(在主机上未安装外壳的变体),从而产生错误。脚本需要bin / bash。
bin / bash主要安装在所有操作系统上。可能是一些路径问题。
还使用条件更新了以下代码。
---
- hosts: localhost
tasks:
- name: Create destination dir if it does not exist
file:
mode: 0775
path: "/usr/local/nvm"
state: directory
when: "nvm_dir is not defined"
- name: Install NVM
shell: 'curl https://raw.githubusercontent.com/creationix/nvm/v0.33.11/install.sh | NVM_SOURCE="" NVM_DIR=/usr/local/nvmPROFILE=/root/.bashrc bash'
args:
warn: false
register: nvm_result