# Expect module won't timeout properly

**URL:** <https://forum.ansible.com/t/expect-module-wont-timeout-properly/28653>\
**Category:** Ansible Project\
**Created:** [September 26, 2018, 8:33am UTC](https://forum.ansible.com/t/expect-module-wont-timeout-properly/28653 "2018-09-26T08:33:34Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![Guillaume\_Jeanne](https://avatars.discourse-cdn.com/v4/letter/g/f05b48/32.png) [@Guillaume\_Jeanne](https://forum.ansible.com/u/Guillaume_Jeanne)\
**Post date:** [September 26, 2018, 8:33am UTC](https://forum.ansible.com/t/expect-module-wont-timeout-properly/28653/1 "2018-09-26T08:33:34Z")

</div>

Hey,

I have a script that i want to use with ansible. This script asks questions so I’m trying to use the expect module as below :

- name: Answer in term to the openvpn script to configure it  
expect:  
command: ./{{ script\_name }}  
responses:  
IP address: ‘51.75.15.139’  
Do you want to enable IPv6 support (NAT)? [y/n]: ‘n’  
Port choice [1-3]: ‘1’  
Protocol [1-2]: ‘1’  
DNS [1-10]: ‘6’  
Enable compression? [y/n]: ‘n’  
Customize encryption settings? [y/n]: ‘n’  
Press any key to continue...: ‘a’  
become: yes

Problem is : At start it took me some times to understand escape char.  
So any time I failed, ansible would timeout and tell me which questions  
in the script had fail. Since then I succeed the second question and  
Ansible told me prob was q.3 (as expected).  
But since i had the other question (even if I had them one by one)  
Ansible won’t timeout but it’s not working properly as it stays in this  
task for ever.  
Anyone would know why it doesn’t timeout and also why it isn’t working ?

---

<div class="post-metadata">

**Author:** ![Kai\_Stian\_Olstad](https://avatars.discourse-cdn.com/v4/letter/k/e19adc/32.png) [@Kai\_Stian\_Olstad](https://forum.ansible.com/u/Kai_Stian_Olstad)\
**Post date:** [September 28, 2018, 8:37pm UTC](https://forum.ansible.com/t/expect-module-wont-timeout-properly/28653/2 "2018-09-28T20:37:28Z")

</div>

> Hey,
> 
> I have a script that i want to use with ansible. This script asks questions  
> so I'm trying to use the expect module as below :
> 
> - name: Answer in term to the openvpn script to configure it  
> expect:  
> command: ./{{ script\_name }}  
> responses:  
> IP address: '51.75.15.139'  
> Do you want to enable IPv6 support \(NAT\)\? \[y\/n\]: 'n'  
> Port choice \[1\-3\]: '1'  
> Protocol \[1\-2\]: '1'  
> DNS \[1\-10\]: '6'  
> Enable compression\? \[y\/n\]: 'n'  
> Customize encryption settings\? \[y\/n\]: 'n'

- aka dash don't need to be escaped, the same goes for / aka slash.

> Press any key to continue\.\.\.: 'a'

On "Press any key" just use ''

> become: yes
> 
> Problem is : At start it took me some times to understand escape char.

You only need to escape regexp special characters.

> So any time I failed, ansible would timeout and tell me which questions  
> in the script had fail. Since then I succeed the second question and  
> Ansible told me prob was q.3 (as expected).  
> But since i had the other question (even if I had them one by one)  
> Ansible won't timeout but it's not working properly as it stays in this  
> task for ever.  
> Anyone would know why it doesn't timeout and also why it isn't working ?

Never had the problem that expect doesn't timeout, you could try to run Ansible with -vvv, but I doubt you get any more information, but worth a shot.

If you remove the unnecessary escapes as mention above and -vvv don't give you any tips you need to debug  
[https://docs.ansible.com/ansible/2.5/dev\_guide/developing\_modules\_general.html?highlight=ansible\_keep\_remote\_files#debugging-remote](https://docs.ansible.com/ansible/2.5/dev_guide/developing_modules_general.html?highlight=ansible_keep_remote_files#debugging-remote)
