1

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?

pynexj
  • 19,215
  • 5
  • 38
  • 56
Wafflecode
  • 45
  • 9

2 Answers2

2

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.

larsks
  • 277,717
  • 41
  • 399
  • 399
  • Yeah, the ansible network modules seem to be closer to what I need. They do have basic expect-like functions. But they seem to be Network OS specific. Hmm. – Wafflecode Feb 25 '19 at 02:51
1

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'
ucipass
  • 923
  • 1
  • 8
  • 21