Ansible Expect - delaybeforesend how to set

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.

  • 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’)"