无法在Debian Stretch上的Ansible 2.7上使用NPM软件包安装PM2

时间:2019-04-11 14:41:38

标签: ansible

我正在基于Debian 9(拉伸)设置新服务器。

我有一个Ansible剧本,当我尝试使用npm ansible模块安装PM2时,它失败了,并且在最近的几天里我一直坚持使用它。

我正在使用ansible 2.7:

ansible 2.7.10
  config file = None
  configured module search path = ['/usr/share/ansible/plugins/modules']
  ansible python module location = /usr/local/lib/python3.7/site-packages/ansible
  executable location = /usr/local/bin/ansible
  python version = 3.7.3 (default, Mar 27 2019, 09:23:15) [Clang 10.0.1 (clang-1001.0.46.3)]

我尝试使用清单上的ansible_python_interpreter=/usr/bin/python3用python 2和3运行该剧本,但是没有运气。

奇怪的是,如果我在服务器上使用ssh并运行npm install pm2 -g,则可以正常运行。 Nvm在服务器上也可以正常工作。

在达到这一点之前,剧本会安装其他几个软件包:

  • mongodb

  • mysql-client

  • redis

  • 各种库

这是剧本的摘录

tasks:
     ...

     - name: Install nvm
      sudo: no
      git: repo=https://github.com/creationix/nvm.git dest=~/.nvm version={{ NVM_VERSION }}
      tags: nvm

    - name: Source nvm in ~/.profile
      sudo: no
      lineinfile: >
        dest=~/.profile
        line="source ~/.nvm/nvm.sh"
        create=yes
      tags: nvm

    - name: Install versions
      shell: bash -lc "nvm install {{ item }}"
      register: output
      changed_when: "'already installed.' not in output.stderr"
      with_items: "{{ NVM_NODE_VERSIONS }}"
      sudo: no

    - name: Set default node version to {{ NVM_DEFAULT_NODE_VERSION }}
      command: sudo -iu admin nvm alias default {{ NVM_DEFAULT_NODE_VERSION }}
      tags: nvm

    - name: Install PM2 packages
      npm:
        executable: /home/admin/.nvm/versions/node/v{{ NVM_DEFAULT_NODE_VERSION }}/bin/npm
        name: pm2
        global: yes
        state: present

....

变量定义如下:

NVM_VERSION : "v0.33.0"
NVM_INSTALL_SCRIPT : "/home/admin/nvm_install.sh"
NVM_NODE_VERSIONS :
 - v10.15.3
 - v6.9.4
 - v8.10.0
 - v8.11.1
NVM_DEFAULT_NODE_VERSION: "10.15.3"

这是我得到的错误:

{  
   "changed":false,
   "module_stderr":"Shared connection to 52.209.248.173 closed.\r\n",
   "module_stdout":"Traceback (most recent call last):\r\n  File \"/home/admin/.ansible/tmp/ansible-tmp-1554992741.43544-36230788449164/AnsiballZ_npm.py\", line 113, in <module>\r\n    _ansiballz_main()\r\n  File \"/home/admin/.ansible/tmp/ansible-tmp-1554992741.43544-36230788449164/AnsiballZ_npm.py\", line 105, in _ansiballz_main\r\n    invoke_module(zipped_mod, temp_path, ANSIBALLZ_PARAMS)\r\n  File \"/home/admin/.ansible/tmp/ansible-tmp-1554992741.43544-36230788449164/AnsiballZ_npm.py\", line 48, in invoke_module\r\n    imp.load_module('__main__', mod, module, MOD_DESC)\r\n  File \"/usr/lib/python3.5/imp.py\", line 234, in load_module\r\n    return load_source(name, filename, file)\r\n  File \"/usr/lib/python3.5/imp.py\", line 170, in load_source\r\n    module = _exec(spec, sys.modules[name])\r\n  File \"<frozen importlib._bootstrap>\", line 626, in _exec\r\n  File \"<frozen importlib._bootstrap_external>\", line 673, in exec_module\r\n  File \"<frozen importlib._bootstrap>\", line 222, in _call_with_frames_removed\r\n  File \"/tmp/ansible_npm_payload_qlnd0iyr/__main__.py\", line 284, in <module>\r\n  File \"/tmp/ansible_npm_payload_qlnd0iyr/__main__.py\", line 261, in main\r\n  File \"/tmp/ansible_npm_payload_qlnd0iyr/__main__.py\", line 185, in list\r\n  File \"/usr/lib/python3.5/json/__init__.py\", line 319, in loads\r\n    return _default_decoder.decode(s)\r\n  File \"/usr/lib/python3.5/json/decoder.py\", line 339, in decode\r\n    obj, end = self.raw_decode(s, idx=_w(s, 0).end())\r\n  File \"/usr/lib/python3.5/json/decoder.py\", line 357, in raw_decode\r\n    raise JSONDecodeError(\"Expecting value\", s, err.value) from None\r\njson.decoder.JSONDecodeError: Expecting value: line 1 column 1 (char 0)\r\n",
   "msg":"MODULE FAILURE\nSee stdout/stderr for the exact error",
   "rc":1
}

清除器错误:

    MODULE FAILURE
    See stdout/stderr for the exact error

    MODULE_STDOUT:

    Traceback (most recent call last):
      File "/home/admin/.ansible/tmp/ansible-tmp-1555331069.891913-182901060644739/AnsiballZ_npm.py", line 113, in <module>
        _ansiballz_main()
      File "/home/admin/.ansible/tmp/ansible-tmp-1555331069.891913-182901060644739/AnsiballZ_npm.py", line 105, in _ansiballz_main
        invoke_module(zipped_mod, temp_path, ANSIBALLZ_PARAMS)
      File "/home/admin/.ansible/tmp/ansible-tmp-1555331069.891913-182901060644739/AnsiballZ_npm.py", line 48, in invoke_module
        imp.load_module('__main__', mod, module, MOD_DESC)
      File "/usr/lib/python3.5/imp.py", line 234, in load_module
        return load_source(name, filename, file)
      File "/usr/lib/python3.5/imp.py", line 170, in load_source
        module = _exec(spec, sys.modules[name])
      File "<frozen importlib._bootstrap>", line 626, in _exec
      File "<frozen importlib._bootstrap_external>", line 673, in exec_module
      File "<frozen importlib._bootstrap>", line 222, in _call_with_frames_removed
      File "/tmp/ansible_npm_payload_qvtn2qwx/__main__.py", line 284, in <module>
      File "/tmp/ansible_npm_payload_qvtn2qwx/__main__.py", line 261, in main
      File "/tmp/ansible_npm_payload_qvtn2qwx/__main__.py", line 185, in list
      File "/usr/lib/python3.5/json/__init__.py", line 319, in loads
        return _default_decoder.decode(s)
      File "/usr/lib/python3.5/json/decoder.py", line 339, in decode
        obj, end = self.raw_decode(s, idx=_w(s, 0).end())
      File "/usr/lib/python3.5/json/decoder.py", line 357, in raw_decode
        raise JSONDecodeError("Expecting value", s, err.value) from None
    json.decoder.JSONDecodeError: Expecting value: line 1 column 1 (char 0)

    MODULE_STDERR:

    OpenSSH_7.9p1, LibreSSL 2.7.3
    debug1: Reading configuration data ~/.ssh/config
    debug1: ~/.ssh/config line 13: Applying options for *
    debug1: Reading configuration data /etc/ssh/ssh_config
    debug1: /etc/ssh/ssh_config line 48: Applying options for *
    debug2: resolve_canonicalize: hostname <ip> is address
    debug1: auto-mux: Trying existing master
    debug2: fd 3 setting O_NONBLOCK
    debug2: mux_client_hello_exchange: master version 4
    debug3: mux_client_forwards: request forwardings: 0 local, 0 remote
    debug3: mux_client_request_session: entering
    debug3: mux_client_request_alive: entering
    debug3: mux_client_request_alive: done pid = 16293
    debug3: mux_client_request_session: session request sent
    debug3: mux_client_read_packet: read header failed: Broken pipe
    debug2: Received exit status from master 1
    Shared connection to <ip> closed.

任何帮助将不胜感激。

1 个答案:

答案 0 :(得分:1)

安装节点的全局版本已解决该问题。