换句话说,可以在原始SSH连接上使用ansible“期望”模块吗?
我正在尝试自动化一些没有完整Python甚至Shell的简单嵌入式设备。有趣的raw
模块适用于简单的命令,但是我想以一种期望的方式来驱动事情。
可以做到吗?
答案 0 :(得分:1)
expect
模块是written in python,所以不行,
Ansible确实有一个模型,可与类似不运行python的设备(例如网络交换机)进行交互;您可以在How Network Automation Is Different中阅读有关内容。我认为这不会为您的问题提供任何立即的解决方案,但是如果与Ansible集成真的很重要,它建议您采用一种寻求解决方案。
仅使用实际的expect
程序而不是Ansible可能会更简单。
答案 1 :(得分:0)
在 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'