[英]Can the Ansible raw ssh module be used like "expect"?
In other words, can the ansible "expect" module be used over a raw SSH connection?换句话说,可以通过原始 SSH 连接使用 ansible“expect”模块吗?
I'm trying automate some simple embedded devices that do not have a full Python or even shell.我正在尝试自动化一些没有完整 Python 甚至 shell 的简单嵌入式设备。 The ansible
raw
module works fine for simple commands, but I'd like to drive things in an expect-like manner. ansible
raw
模块适用于简单的命令,但我想以类似期望的方式驱动事情。
Can this be done?这能做到吗?
The expect
module is written in python , so no, that won't work. expect
模块是用 python 编写的,所以不,那是行不通的。
Ansible does have a model for interacting with devices like network switches that similarly don't run python; Ansible 确实有一个模型可以与类似不运行 python 的网络交换机等设备进行交互; you can read about that in the How Network Automation Is Different .
您可以在网络自动化的不同之处阅读相关内容。 I don't think that will offer any sort of immediate solution to your problem, but it suggests a way of pursuing things if it was really important to integrate with Ansible.
我认为这不会为您的问题提供任何直接的解决方案,但如果与 Ansible 集成真的很重要,它会提出一种追求事物的方式。
It would probably be simpler to just use the actual expect
program instead of Ansible.使用实际的
expect
程序而不是 Ansible 可能会更简单。
With Ansible 2.7 and up, you can use the cli_command module.在Ansible 2.7及更高版本中,您可以使用 cli_command 模块。 It's kind of like 'expect' and it does not need python on the target.
它有点像“期望”,它不需要目标上的python。 https://docs.ansible.com/ansible/latest/modules/cli_command_module.html
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'
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.