【发布时间】:2019-07-15 22:01:44
【问题描述】:
换句话说,可以通过原始 SSH 连接使用 ansible "expect" 模块吗?
我正在尝试自动化一些没有完整 Python 甚至外壳的简单嵌入式设备。 ansible raw 模块适用于简单的命令,但我想以类似期望的方式驱动。
这个可以吗?
【问题讨论】:
标签: python ansible pexpect pxssh
换句话说,可以通过原始 SSH 连接使用 ansible "expect" 模块吗?
我正在尝试自动化一些没有完整 Python 甚至外壳的简单嵌入式设备。 ansible raw 模块适用于简单的命令,但我想以类似期望的方式驱动。
这个可以吗?
【问题讨论】:
标签: python ansible pexpect pxssh
expect 模块是 written in python,所以不,这不起作用。
Ansible 确实有一个模型用于与类似不运行 python 的网络交换机等设备进行交互;您可以在How Network Automation Is Different 中阅读相关内容。我认为这不会为您的问题提供任何直接的解决方案,但如果与 Ansible 集成真的很重要,它会建议一种追求事物的方法。
只使用实际的 expect 程序而不是 Ansible 可能会更简单。
【讨论】:
使用 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'
【讨论】: