执行 pm2 启动命令的 Ansible 错误
Ansible error executing pm2 startup command
使用命令执行ansible playbook时:ansible-playbook 2_installJsReport.yml
CentOS 7.6
Ansible 2.7.10
我收到一条错误消息:
TASK [make jsreport start at system restart] >*****************************************************************************>**************************************
fatal: [localhost]: FAILED! => {"changed": true, "cmd": ["pm2", "startup"], >"delta": "0:00:00.601130", "end": "2019-04-24 12:59:33.091819", "msg": "non->zero return code", "rc": 1, "start": "2019-04-24 12:59:32.490689", "stderr": >"", "stderr_lines": [], "stdout": "[PM2] Init System found: systemd\n[PM2] To >setup the Startup Script, copy/paste the following command:\nsudo env >PATH=$PATH:/home/username/.nvm/versions/node/v8.11.3/bin >/home/username/.nvm/versions/node/v8.11.3/lib/node_modules/pm2/bin/pm2 >startup systemd -u username --hp /home/username", "stdout_lines": ["[PM2] >Init System found: systemd", "[PM2] To setup the Startup Script, copy/paste >the following command:", "sudo env >PATH=$PATH:/home/username/.nvm/versions/node/v8.11.3/bin >/home/username/.nvm/versions/node/v8.11.3/lib/node_modules/pm2/bin/pm2 >startup systemd -u username --hp /home/username"]}
Ansible 脚本
---
- hosts: localhost
tasks:
- name: make jsreport start at system restart
command: pm2 startup
"error" 消息包含配置启动时应遵循的说明:
[PM2] Init System found: systemd
[PM2] To setup the Startup Script, copy/paste the following command:
sudo env PATH=$PATH:/home/username/.nvm/versions/node/v8.11.3/bin /home/username/.nvm/versions/node/v8.11.3/lib/node_modules/pm2/bin/pm2 startup systemd -u username --hp /home/username
如果您按照这些说明进行操作,它会建议您将任务替换为类似以下内容:
---
- hosts: localhost
tasks:
- name: make jsreport start at system restart
become: true
command: pm2 startup systemd -u username --hp /home/username
environment:
PATH: "{{ ansible_env.PATH }}"
使用命令执行ansible playbook时:ansible-playbook 2_installJsReport.yml
CentOS 7.6
Ansible 2.7.10
我收到一条错误消息:
TASK [make jsreport start at system restart] >*****************************************************************************>************************************** fatal: [localhost]: FAILED! => {"changed": true, "cmd": ["pm2", "startup"], >"delta": "0:00:00.601130", "end": "2019-04-24 12:59:33.091819", "msg": "non->zero return code", "rc": 1, "start": "2019-04-24 12:59:32.490689", "stderr": >"", "stderr_lines": [], "stdout": "[PM2] Init System found: systemd\n[PM2] To >setup the Startup Script, copy/paste the following command:\nsudo env >PATH=$PATH:/home/username/.nvm/versions/node/v8.11.3/bin >/home/username/.nvm/versions/node/v8.11.3/lib/node_modules/pm2/bin/pm2 >startup systemd -u username --hp /home/username", "stdout_lines": ["[PM2] >Init System found: systemd", "[PM2] To setup the Startup Script, copy/paste >the following command:", "sudo env >PATH=$PATH:/home/username/.nvm/versions/node/v8.11.3/bin >/home/username/.nvm/versions/node/v8.11.3/lib/node_modules/pm2/bin/pm2 >startup systemd -u username --hp /home/username"]}
Ansible 脚本
---
- hosts: localhost
tasks:
- name: make jsreport start at system restart
command: pm2 startup
"error" 消息包含配置启动时应遵循的说明:
[PM2] Init System found: systemd
[PM2] To setup the Startup Script, copy/paste the following command: sudo env PATH=$PATH:/home/username/.nvm/versions/node/v8.11.3/bin /home/username/.nvm/versions/node/v8.11.3/lib/node_modules/pm2/bin/pm2 startup systemd -u username --hp /home/username
如果您按照这些说明进行操作,它会建议您将任务替换为类似以下内容:
---
- hosts: localhost
tasks:
- name: make jsreport start at system restart
become: true
command: pm2 startup systemd -u username --hp /home/username
environment:
PATH: "{{ ansible_env.PATH }}"