【问题标题】:ansible installing npm using nvm but returning npm command not found on npm installansible 使用 nvm 安装 npm 但在 npm install 上找不到 npm 命令
【发布时间】:2019-06-28 10:06:58
【问题描述】:

我正在尝试在 Ubuntu 18.04.2 LTS 上使用 ansible playbook 脚本安装 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)

【问题讨论】:

    标签: npm ansible nvm


    【解决方案1】:

    默认情况下,shell 模块使用/bin/sh,除非可执行文件已在模块中使用 args/keyword 显式定义。

    看起来像/bin/bash(主机上没有安装shell的变体)从而给出错误。脚本需要 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
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2016-02-08
      • 2022-01-05
      • 2019-06-26
      • 2017-12-19
      • 1970-01-01
      • 2017-05-14
      • 1970-01-01
      • 2014-01-13
      相关资源
      最近更新 更多