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>
BASE>w abc
w abc
BASE>h
I run the same program using Ansible Expect with this playbook:
---
- name: Test a conversation
hosts: BASE
remote_user: root
gather_facts: false
tasks:
- name: Copy script converse2.py
copy: src=/home/converse2.py
dest=/home/converse2.py
remote_src=no
mode=preserve
- name: Run test session
expect:
echo: yes
chdir: /tmp
command: python3 /home/converse2.py
timeout: "300"
responses:
Username: sq
Password: "SoLong>"
BASE\>: w ##Class(websys).test()
BASE\>: H
register: command_output
- debug:
msg: "{{ command_output.stdout.split('\n') }}"
However Ansible Expect is not sending 'w ##Class(websys).test()' to the program
This is the run:
ansible-playbook /home/ansible_playbooks/test-converse2.yml
[WARNING]: While constructing a mapping from /home/ansible_playbooks/test-converse2.yml, line 20, column 9, found a duplicate dict key (BASE\>). Using last defined value only.
PLAY [Test a conversation] ****************************************************************************************************************************************************
TASK [Copy script converse2.py] ***********************************************************************************************************************************************
ok: [TRAK-BASE01]
TASK [Run test session] ********************************************************************************************************************************************************
changed: [TRAK-BASE01]
TASK [debug] ********************************************************************************************************************************************************************
ok: [TRAK-BASE01] => {
"msg": [
"\r",
"Welcome to BASE\r",
" My configuration is up to date\r",
" Print settings are normal\r",
"\r",
"\r",
"Username: sq\r",
"Password: SoLong>\r",
"BASE>H"
]
}
PLAY RECAP ************************************************************************************************************************************************************************
TRAK-BASE01 : ok=3 changed=1 unreachable=0 failed=0 skipped=0 rescued=0 ignored=0
How do I fix this?