简体   繁体   English

Ansible 原始 ssh 模块可以像“期望”一样使用吗?

[英]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.

相关问题 在使用python ansible模块为新主机执行ansible剧本时,我们能否忽略要求在.ssh目录中添加主机的问题? - Can we ignore asking to add host in .ssh directory while executing ansible playbook using python ansible module for a new host? 如何使用ansible&#39;expect&#39;模块进行多种不同的响应? - How to use ansible 'expect' module for multiple different responses? Ansible community.general.ssh_config: ModuleNotFoundError: No module named 'storm' - Ansible community.general.ssh_config: ModuleNotFoundError: No module named 'storm' 开发的Ansible模块可以包含或扩展Ansible Core模块吗? - Can a developed Ansible module include or extend an Ansible Core module? 如何创建一个可以像 module.subsection.function() 一样使用的模块? - How do I create a module that can be used like module.subsection.function()? ansible docker-compose 模块,ansible 的结果与主机上的 ssh 不同 - ansible docker-compose module, different result from ansible than over ssh on the host 我如何在Ansible SSH之前获取bashrc - How can i source bashrc before ansible ssh sum()是否可以像哈希一样使用 - Can sum() be used like a hash QMenu 可以像按钮一样使用吗 - Can a QMenu be used like a Button Ansible - 我可以在模块执行期间打印信息吗? - Ansible - Can I print information during module execution?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM