# Ansible Expect - delaybeforesend how to set

**URL:** <https://forum.ansible.com/t/ansible-expect-delaybeforesend-how-to-set/37412>\
**Category:** Ansible Project\
**Created:** [December 2, 2022, 2:58am UTC](https://forum.ansible.com/t/ansible-expect-delaybeforesend-how-to-set/37412 "2022-12-02T02:58:34Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![Phillip\_Wu](https://avatars.discourse-cdn.com/v4/letter/p/f4b2a3/32.png) [@Phillip\_Wu](https://forum.ansible.com/u/Phillip_Wu)\
**Post date:** [December 2, 2022, 2:58am UTC](https://forum.ansible.com/t/ansible-expect-delaybeforesend-how-to-set/37412/1 "2022-12-02T02:58:34Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![atul\_mohan](https://avatars.discourse-cdn.com/v4/letter/a/f04885/32.png) [@atul\_mohan](https://forum.ansible.com/u/atul_mohan)\
**Post date:** [August 25, 2023, 4:10am UTC](https://forum.ansible.com/t/ansible-expect-delaybeforesend-how-to-set/37412/2 "2023-08-25T04:10:23Z")

</div>

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