Ansible Expect - Program under control has same prompt

Hi,
I want to run a program on a remote server where after login, the program will ask for more input using the same prompt.

This is the basic flow:
Read Username
Read Password
Read commands ← these get echoed back
until ‘h’ or ‘H’ is entered

This is a sample run of the program
BASE:/home# python3 converse2.py
Welcome to BASE
My configuration is up to date
Print settings are normal
Username: sq
Password: SoLong>

w abc
w abc
h

I run the same program using Ansible Expect with this playbook:

Your responses is now a dict which cannot have the same key more than once. So the second BASE question isn’t going to work.
Try turning it into a list.
See https://docs.ansible.com/ansible/latest/collections/ansible/builtin/expect_module.html#examples

Thanks. That did the trick.

I changed

BASE>: w ##Class(websys).test()
BASE>: H

to
BASE>: [“w ##Class(websys.PatchHistory).test()”,“H”]

However, how do I code the list if I have this set of prompts:
BASE1>
BASE1>
BASE1>
BASE2>
BASE2>
BASE1>
BASE1>

Hi

It now partly works because you made the items of a single dict key into a list and by doing so also quoted the value with ‘#’ in it.
But what I meant is to have the responses itself be a list, so you can have duplicates. I think this would look like:

responses:

  • Username: sq

  • Password: “SoLong>”

  • BASE>: “w ##Class(websys).test()”

  • BASE>: “H”

  • BASE1>: “foo”

  • BASE1>: “bar”

  • BASE1>: “bz”

  • BASE2>: “fog”

  • BASE2>: “fbzhy33”

  • BASE1>: “bar”

etc

Thanks.

I tried what you suggested but I get:
‘responses’ is of type <class ‘list’> and we were unable to convert to dict

But this seems to work:
responses:

Username: sq
Password: “SoLong>”
BASE>:

  • “w ##Class(websys).test()”
  • “H”

Then i don’t know, perhaps someone else does