Hello All,
trying to understand expect functionality using below piece of code… I know I can do using becom_user, but I would like to check expect module… since there is requirement where I need to use expect module for automating client app CLI
tasks:
- name: testing expect
expect:
command: sudo su
responses:
‘(?)password’: “password”
'(?)’: ls
timeout: 30
echo: yes
task is hanged and not continued further. Any suggestions are highly welcome.
In your specific case where pexpect is working on the remote system (else you would have got an error),
perhaps the problem is that you are not exiting from the shell?
Instead of just "ls", try "ls; exit"
HTH,
Sandip
P.S. I once had a similar problem, with the additional constraint that the right version of python-expect
was not available on the remote system. So I had to use the system expect executable.
I documented my solution here:
https://blog.sandipb.net/2019/06/14/ansible-privilege-escalation-with-expect-when-you-dont-have-root-shell-privileges/
but unfortunately, expect package is not installed on target nodes and even not allowed too. only I have to use ansible built in module.
I tried ls;exit… but still the same issue.