带有 nvm 的 Ansible 安装节点

eth*_*it3 4 node.js nvm ansible

我正在寻找一种通过 ansible 和 nvm 安装给定版本节点的方法,nvm 的安装按预期工作,因为如果我与 root 用户连接,我可以执行命令 nvm install 8.11.3 但这个命令是相同的不适用于 Ansible,我不明白为什么。

---
- name: Install nvm
  git: repo=https://github.com/creationix/nvm.git dest=~/.nvm version=v0.33.11
  tags: nvm

- name: Source nvm in ~/.{{ item }}
  lineinfile: >
      dest=~/.{{ item }}
      line="source ~/.nvm/nvm.sh"
      create=yes
  tags: nvm
  with_items:
    - bashrc
    - profile

- name: Install node and set version
  become: yes
  become_user: root
  shell: nvm install 8.11.3
...
Run Code Online (Sandbox Code Playgroud)

错误日志

TASK [node : Install node and set version] *************************************************************************************
    fatal: [51.15.128.164]: FAILED! => {"changed": true, "cmd": "nvm install 8.11.3", "delta": "0:00:00.005883", "end": "2018-12-03 15:05:10.394433", "msg": "non-zero return code", "rc": 127, "start": "2018-12-03 15:05:10.388550", "stderr": "/bin/sh: 1: nvm: not found", "stderr_lines": ["/bin/sh: 1: nvm: not found"], "stdout": "", "stdout_lines": []}
        to retry, use: --limit .../.../ansible/stater-debian/playbook.retry
Run Code Online (Sandbox Code Playgroud)

eth*_*it3 9

没关系,这是有效的配置

- name: Install node and set version
  become: yes
  become_user: root
  shell: "source /root/.nvm/nvm.sh && nvm install 8.11.3" 
  args:
    executable: /bin/bash
Run Code Online (Sandbox Code Playgroud)

  • 你住在哪里我想送你一份礼物 (3认同)