代码之家  ›  专栏  ›  技术社区  ›  unsafe_where_true

Ansible:在本地运行一个交互式shell脚本

  •  0
  • unsafe_where_true  · 技术社区  · 5 年前

    我有一个交互式构建shell脚本,其中包含以下部分:

    echo "Is this correct?"
    select yn in "Yes" "No"; do
        case $yn in
            Yes ) break;;
            No ) exit;;
        esac
    done
    

    如果我自己运行脚本( ./runscript.sh ),然后我得到正确的提示。

    但如果我从ansible内部运行shell脚本,如下所示:

      tasks:
        - name: Run script
          shell: "./runscript.sh {{param1}} {{param2}} {{param3}}"
          args:
              chdir: "../../path/to/script/"
          run_once: true
          delegate_to: localhost
    

    然后这件事就发生了,我没有得到任何提示,我也不知道发生了什么。完成了吗?如何,使用什么设置?它总是含蓄地假设“是”吗?

    0 回复  |  直到 5 年前
        1
  •  1
  •   lainatnavi    5 年前

    shell模块执行失败。如果你打印 rc 对于脚本执行,它应该不同于0。
    原因是外壳模块 runs the command through a shell (/bin/sh) 虽然 select 是一个Bash构造。