【问题标题】:Can the Ansible raw ssh module be used like "expect"?Ansible raw ssh 模块可以像“expect”一样使用吗?
【发布时间】:2019-07-15 22:01:44
【问题描述】:

换句话说,可以通过原始 SSH 连接使用 ansible "expect" 模块吗?

我正在尝试自动化一些没有完整 Python 甚至外壳的简单嵌入式设备。 ansible raw 模块适用于简单的命令,但我想以类似期望的方式驱动。

这个可以吗?

【问题讨论】:

    标签: python ansible pexpect pxssh


    【解决方案1】:

    expect 模块是 written in python,所以不,这不起作用。

    Ansible 确实有一个模型用于与类似不运行 python 的网络交换机等设备进行交互;您可以在How Network Automation Is Different 中阅读相关内容。我认为这不会为您的问题提供任何直接的解决方案,但如果与 Ansible 集成真的很重要,它会建议一种追求事物的方法。

    只使用实际的 expect 程序而不是 Ansible 可能会更简单。

    【讨论】:

    • 是的,ansible 网络模块似乎更接近我的需要。它们确实具有基本的类似期望的功能。但它们似乎是特定于网络操作系统的。嗯。
    【解决方案2】:

    使用 Ansible 2.7 及更高版本,您可以使用 cli_command 模块。这有点像“期望”,它不需要在目标上使用 python。 https://docs.ansible.com/ansible/latest/modules/cli_command_module.html

    - name: multiple prompt, multiple answer (mandatory check for all prompts)
      cli_command:
        command: "copy sftp sftp://user@host//user/test.img"
        check_all: True
        prompt:
          - "Confirm download operation"
          - "Password"
          - "Do you want to change that to the standby image"
        answer:
          - 'y'
          - <password>
          - 'y'
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2010-10-27
      • 2014-09-10
      • 2015-02-07
      • 2018-11-04
      • 1970-01-01
      • 2016-10-17
      相关资源
      最近更新 更多