【问题标题】:How to pass input to interactive command using ansible?如何使用ansible将输入传递给交互式命令?
【发布时间】:2020-05-16 21:02:39
【问题描述】:

我有一个要在 Unix 服务器上执行的命令。该命令期望用户在两点输入,然后继续进行。命令如下:

$ abc_1.2_udate.bin /tmp/log

  Do you want to proceed y/n?
  y

  Please provide the credentials:
  1234

从ansible尝试如下:

  - name: execute the cmnd

    expect:

       Command: abc_1.2_udate.bin /tmp/log

       responses:

          Do you want to proceed y/n? "y"

          'Please provide the credentials:' "1234"

但是上面的部分不起作用。我也只想为此使用 expect 模块。

【问题讨论】:

  • 您的示例任务不是有效的期望模块调用,既不是有效的 ansible 任务定义,也不是有效的 yaml 表示。请在阅读相关文档/参考后查看您的剧本,修复明显的错误,再次运行它,如果您仍然有问题,最终使用确切的错误消息编辑您的问题。 does not work 永远不能准确描述您的问题。

标签: unix ansible command yaml expect


【解决方案1】:
  1. 将命令更改为命令(C 不是大写字母)
  2. 应以'Enter': "y" 格式在引号中给出响应
expect:
 command: abc_1.2_udate.bin /tmp/log
 responses:
  'Do you want to proceed y/n?': "y"
  'Please provide the credentials': "1234"

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-11-20
    • 2017-11-30
    • 2016-05-22
    相关资源
    最近更新 更多