Reputation: 231
My Ansible code:
- expect:
command: virsh console myguest
responses:
'Escape character is': ''
'login:': 'root'
'root@:~ #': 'cli'
'root>': 'show version'
register: myreg
- debug: msg="{{ myreg.stdout_lines }}"
Execution of the code above showed each of my responses were feed twice. See sample outputs below:
"login: root",
"Last login: Mon May 10 03:57:15 on ttyu0",
"",
"root@:~ # root",
"",
"root: Command not found.",
"root@:~ # cli",
"",
"cli",
"root> cli",
" ^",
"unknown command.",
"",
"root> show version ",
......
Although the wrong feedings were not recognized so the results were still usable, but what might be wrong that caused the double feeds?
Upvotes: 0
Views: 351
Reputation: 33231
You have an ambiguous regex:
"Last login: Mon May 10 03:57:15 on ttyu0",
for sure matches login:
just with a Last
prefix
You likely want:
...
responses:
'^login:': 'root'
'^root@:~ #': 'cli'
since in your examples those strings occur at the leading edge of the output.
The rest of the malformity you're encourtering may straighten itself out once you and expect are on the same page
Upvotes: 2