Ansible Expect - delaybeforesend how to set

52 views
Skip to first unread message

phillip.from.oz

unread,
Dec 1, 2022, 9:58:34 PM12/1/22
to Ansible Project
Hi,
I undestand that 'Ansible Expect' uses python pexpect.

Do you know if ansible playbook can change pexpect's 'delaybeforesend'?

' delaybeforesend' is used to wait a little time before sending a response to a prompt.
The reason for this sometimes my Ansible Expect playbook works and sometimes the same playbook fails. I think this is a timing issue when the program on the remote side is a bit slow.


Atul Nasir

unread,
Aug 25, 2023, 12:10:23 AM8/25/23
to Ansible Project
- name: Set delaybeforesend using pexpect
  hosts: your_target_host
  tasks:
    - name: Run the command with pexpect and set delaybeforesend
      shell: |
        python -c "
        import pexpect
        child = pexpect.spawn('your_command_here')
        child.delaybeforesend = 0.5  # Set the desired delay
        child.expect('expected_prompt')
        child.sendline('response')"
Reply all
Reply to author
Forward
0 new messages