Thanks That's a pity.
The prompt is different on each host that I'll be adding (later) On Fri, Dec 2, 2022 at 1:37 AM Matt Martz <[email protected]> wrote: > Generally speaking, you cannot set keys anywhere in ansible to a template, > this is simply just not allowed. > > As such, there really isn't a mechanism for doing this. Keys must be > hardcoded. > > On Thu, Dec 1, 2022 at 3:15 AM phillip.from.oz <[email protected]> > wrote: > >> 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 >> <https://groups.google.com/d/msgid/ansible-project/e8b0cfe2-6704-45db-b87c-68da18ba4e94n%40googlegroups.com?utm_medium=email&utm_source=footer> >> . >> > > > -- > Matt Martz > @sivel > sivel.net > > -- > You received this message because you are subscribed to a topic in the > Google Groups "Ansible Project" group. > To unsubscribe from this topic, visit > https://groups.google.com/d/topic/ansible-project/-rdOecvL51w/unsubscribe. > To unsubscribe from this group and all its topics, send an email to > [email protected]. > To view this discussion on the web visit > https://groups.google.com/d/msgid/ansible-project/CAD8N0v9ts_6KwDRWQgjW4wEknNNkwo_1WSSPFv4JdjER9_zftg%40mail.gmail.com > <https://groups.google.com/d/msgid/ansible-project/CAD8N0v9ts_6KwDRWQgjW4wEknNNkwo_1WSSPFv4JdjER9_zftg%40mail.gmail.com?utm_medium=email&utm_source=footer> > . > -- 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/CAJVgDZa6QFO2L%2BshC3_i%3DvbVFAJ2W7OHM%2BuFWecm6_a02SohLg%40mail.gmail.com.
