找不到内部脚本命令的

找不到内部脚本命令的

本文介绍了找不到内部脚本命令的 Ansible的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

可靠:

-   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

脚本文件:

#!/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;

当我尝试在远程机器上运行 pm2 命令时,它正在工作.但是,不是从 ansible 脚本文件运行.

When I tried to run pm2 command on the remote machine, It's working. But, not running from ansible script file.

错误:

致命:[网络服务器]:失败!=> {"changed": true, "failed": true, "msg": "非零返回码", "rc": 1, "stderr": "与 xx.xx.xx.xx 的共享连接已关闭.\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"]}

推荐答案

您正在覆盖脚本中的 PATH 环境变量.这用于确定可执行文件的位置(参见 https://en.wikipedia.org/wiki/PATH_(变量)).

You're overwriting the PATH environment variable in your script. This is used to determine where executables are located (see https://en.wikipedia.org/wiki/PATH_(variable)).

简短的回答是在脚本中为 PATH 使用不同的名称,并为脚本中的命令使用绝对路径.

Short answer is to use a different name for PATH in your script and use absolute paths for commands in your script.

这篇关于找不到内部脚本命令的 Ansible的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-12 19:07