【问题标题】:is it possible to run a shell script from ansible role/file directory?是否可以从 ansible 角色/文件目录运行 shell 脚本?
【发布时间】:2020-02-03 02:23:24
【问题描述】:

我有一个角色需要运行一个shell脚本test.sh保存在角色的文件目录下,我的任务如下所示

我收到以下错误

name: 执行shell脚本 命令:sh test.sh

失败了! => {“改变”:真,“cmd”:[“sh”,“test.sh”],“delta”: “0:00:00.008077”,“结束”:“2019-10-04 14:23:39.800839”,“味精”: “非零返回码”,“rc”:127,“start”:“2019-10-04 14:23:39.792762", "stderr": "sh: test.sh: 没有这样的文件或目录", “stderr_lines”:[“sh:test.sh:没有这样的文件或目录”],“stdout”: "", "stdout_lines": []}

【问题讨论】:

    标签: shell ansible roles ansible-role


    【解决方案1】:

    你可以试试:

    script 模块:

    - name: Execute shell script
      script: test.sh
    

    根据 Ansible 文档

    • 脚本模块采用脚本名称后跟以空格分隔的参数列表。
    • path 处的本地脚本将被传输到远程节点然后执行。
    • 将通过远程节点上的 shell 环境处理给定的脚本。
    • 此模块不需要远程系统上的 python,很像原始模块。

    【讨论】:

      猜你喜欢
      • 2018-08-25
      • 2010-09-10
      • 2011-03-13
      • 1970-01-01
      • 1970-01-01
      • 2010-12-12
      • 1970-01-01
      • 2012-06-03
      • 1970-01-01
      相关资源
      最近更新 更多