Reputation: 55
In other words, can the ansible "expect" module be used over a raw SSH connection?
I'm trying automate some simple embedded devices that do not have a full Python or even shell. The ansible raw
module works fine for simple commands, but I'd like to drive things in an expect-like manner.
Can this be done?
Upvotes: 2
Views: 1759
Reputation: 1068
With Ansible 2.7 and up, you can use the cli_command module. It's kind of like 'expect' and it does not need python on the target. 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'
Upvotes: 2
Reputation: 312530
The expect
module is written in python, so no, that won't work.
Ansible does have a model for interacting with devices like network switches that similarly don't run 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.
It would probably be simpler to just use the actual expect
program instead of Ansible.
Upvotes: 2