phillip.from.oz
unread,Dec 1, 2022, 4:15:15 AM12/1/22Sign in to reply to author
Sign in to forward
You do not have permission to delete messages in this group
Either email addresses are anonymous for this group or you need the view member email addresses permission to view the original message
to Ansible Project
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