Here's my Ansible playbook:
- name: Node package manager
npm:
name: pm2
global: yes
notify:
- restart nginx
- name: start the app
script: ../files/common/pm2.sh app_name {{ user }}
tags: test
and here's the script file:
#!/bin/bash
APP_NAME=$1
USER=$2
if [ "$USER" != "" ]; then
PATH="/home/$USER/"
else
PATH="/var/www/"
fi
pm2 describe ${APP_NAME} > /dev/null # line no 11
RUNNING=$?
if [ "${RUNNING}" -ne 0 ]; then
cd ${PATH}${APP_NAME}/ && pm2 start npm --name "${APP_NAME}" -- start
else
pm2 restart ${APP_NAME}
fi;
But when I try to run pm2 command on the remote machine, it works, but if I do the same using ansible script this comes up
Error:
fatal: [webserver]: FAILED! => {"changed": true, "failed": true, "msg": "non-zero return code", "rc": 1, "stderr": "Shared connection to xx.xx.xx.xx closed.\r\n", "stdout": "/home/ronak/.ansible/tmp/ansible-tmp-1510939424.06-225768915266978/pm2.sh: line 11: pm2: command not found\r\n127\r\n", "stdout_lines": ["/home/ronak/.ansible/tmp/ansible-tmp-1510939424.06-225768915266978/pm2.sh: line 11: pm2: command not found", "127"]}