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>
On Wednesday, November 30, 2022 at 4:02:42 PM UTC+11 [email protected] 
wrote:

> 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
>
>
>
>
> On Wed, 30 Nov 2022 at 02:03, phillip.from.oz <[email protected]> 
> wrote:
>
>> 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?
>>
>> -- 
>> You received this message because you are subscribed to the Google Groups 
>> "Ansible Project" group.
>> To unsubscribe from this group and stop receiving emails from it, send an 
>> email to [email protected].
>> To view this discussion on the web visit 
>> https://groups.google.com/d/msgid/ansible-project/38895202-0733-4df4-8d11-1c661128f3f7n%40googlegroups.com
>>  
>> <https://groups.google.com/d/msgid/ansible-project/38895202-0733-4df4-8d11-1c661128f3f7n%40googlegroups.com?utm_medium=email&utm_source=footer>
>> .
>>
> -- 
> Sent from Gmail Mobile
>

-- 
You received this message because you are subscribed to the Google Groups 
"Ansible Project" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/ansible-project/62b8e9c3-cae8-4e95-83f3-fcaa8f95aed1n%40googlegroups.com.

Reply via email to