Raw module and interactive commands

Is it possible to use the raw module to interactively enter text? For example, I’m trying to manage a switch and one of the commands ask a yes/no question. Is it possible to enter a “y” right after invoking the command? I tried to create a playlist using raw: “save primary\ny” but that didn’t work.

James

No, its completely batch, you can try the expect module for interactive prompts.

What switch are you trying to send commands to?

We have started to incorporate network device support into the module_utils for connecting to interactive devices over ssh with initial support for IOS based devices. See here for the IOS shared module support (https://github.com/ansible/ansible/pull/13358/files) and here (https://github.com/ansible/ansible-modules-core/pull/2587/files) for an example module

Extreme Networks’ EXOS. It’s Linux based but doesn’t have Python or other languages except one that I can’t remember it’s heritage (TCL maybe?). I think the prompt is a heavily modified BusyBox or something.

I’m not sure how I would go about testing those 2 modules. I could try them if you think they might work. I can use the raw module to send commands and get back results, I just can’t find any way around some of the interactive prompts.

I believe Extreme is working on adding Ansible support to their OS, but my switches won’t can’t be upgraded to any newer versions so I can’t get those updates.

That's great news, especially as I have written an ugly bit of bash this
week to bulk unset and reset the correct ntp servers on all out Cisco
switches...

Is there a tutorial anywhere about how to get started using the expect module? I’ve installed pexpect but when I try to use it in a playbook it fails with this message:

ERROR: expect is not a legal parameter in an Ansible task or handler

Based on what I’ve found (I could only find 2-3 examples, there doesn’t seem to be any documentation other than https://docs.ansible.com/ansible/expect_module.html, which doesn’t adequately explain how to use it), the playbook should look something like this.

tasks:

  • expect:
    command: save primary
    responses:
    Do you want to save configuration to primary.cfg and overwrite it? (y/N): “Y”

Am I missing something? This page says that the extra’s modules is shipped with ansible, is that still accurate? https://docs.ansible.com/ansible/modules_extra.html

James

On investigation it appears that I do not have the expect module. I thought I installed ansible with pip install ansible, but I earlier tried homebrew but it didn’t work. Maybe something got messed up. I guess I’ll try to figure out how to fix my installation.

The Ansible expect module will be shipped with 2.0. The current released version is 1.9.4.

I’ve uninstalled and reinstalled version 1.9.4 and it isn’t with it. I downloaded it from github and added “library = /path/to/ansible/modules:/path/to/extras” to the ansible.cfg file, had to fix my command to the following text

  • expect:
    command: save primary
    responses:
    Do you want to save configuration to primary.cfg and overwrite it? (y/N): “Y”

but I still get an error. It looks like ansible is still trying to copy a file to the switch. The switches don’t allow files to be copied to them. I’m guessing I can’t use the expect module after all.

It still won't work with the switch as it is a module, which NEEDS to
be copied to the target and then executed via python, raw is the only
'module' that does not do this, it is really a special case inside
Ansible and not a real module.

In 2.0 we are adding the scaffolding to deal with switches, we will
also be adding modules to manage them that take into account the
quirks they have.

Awesome, thank you for the information.

In 2.0 we have module_utils/ssh.py (to be renamed) that is the core of shared code for future modules that will deal with that kind of switch.