Hi,
I'm trying to set Ansible Expect prompt to a variable in host file.

However this does not work.

You can see that Ansible is not sending a response to the prompt.
The prompt is defined as the contents of a variable declared in host file.

Can someone see what is wrong?

=======================================
This is the host file:
[trak]
BASE prompt="BASE\>"

This is the Ansible playbook:
---
- name: Test a conversation
  hosts: BASE
  remote_user: root
  gather_facts: false

  tasks:
  - name: Copy script converse.py
    copy: src=/home/converse.py
            dest=/home/converse.py
            remote_src=no
            mode=preserve
  - name: Run test session
    expect:
      echo: yes
      chdir: /tmp
      command: python3 /home/converse.py
      timeout: "300"
      responses:
        Username: sq
        Password: "MeMe"
        "{{hostvars[inventory_hostname].prompt}}": ["w 
##Class(websys).test()","H"]
    register: command_output
  - debug:
      msg: "{{ command_output.stdout.split('\n') }}"




This is the result:
# ansible-playbook test-converse.yml

PLAY [Test a conversation] 
********************************************************************

TASK [Copy script converse.py] 
****************************************************************
changed: [BASE]

TASK [Run test session] 
***********************************************************************
fatal: [BASE]: FAILED! =>
               {"changed": true, "cmd": "python3 converse.py", "delta": 
"0:05:00.340507",
                "end": "2022-12-01 19:12:18.727066", "msg": "command 
exceeded timeout", 
                "rc": null, "start": "2022-12-01 19:07:18.386559",
                "stdout": "\r\nWelcome to BASE\r\n   My configuration is up 
to date\r\n
                           Print settings are normal\r\n\r\n\r\n
                Username: sq\r\n
                Password: MeMe\r\n
                BASE>",
                "stdout_lines": ["", "Welcome to BASE", "   My 
configuration is up to date",
                "   Print settings are normal", "", "",
                "Username: sq", "Password: MeMe", "BASE>"]}

PLAY RECAP 
**************************************************************************************
BASE     : ok=1    changed=1    unreachable=0    failed=1    skipped=0   
 rescued=0    ignored=0

-- 
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/e8b0cfe2-6704-45db-b87c-68da18ba4e94n%40googlegroups.com.

Reply via email to