# expect module hangs

**URL:** <https://forum.ansible.com/t/expect-module-hangs/26912>\
**Category:** Ansible Project\
**Created:** [March 6, 2018, 5:15pm UTC](https://forum.ansible.com/t/expect-module-hangs/26912 "2018-03-06T17:15:12Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![DOkuwa](https://sea1.discourse-cdn.com/ansible/user_avatar/forum.ansible.com/dokuwa/32/1471_2.png) [@DOkuwa](https://forum.ansible.com/u/DOkuwa)\
**Post date:** [March 6, 2018, 5:15pm UTC](https://forum.ansible.com/t/expect-module-hangs/26912/1 "2018-03-06T17:15:12Z")

</div>

Hello

I have a config to copy config to a tftp server  
but with the expect module  
it just hangs no error  
it logs it successful with telnet( I can see it in the logs) but does not copy ( I have tested it manually with ftp)  
please tell me where I am going wrong

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/ansible/original/1X/1882d9a01da5d8996a862359b0913cc568a39b84.svg) [@system](https://forum.ansible.com/u/system)\
**Post date:** [March 6, 2018, 6:06pm UTC](https://forum.ansible.com/t/expect-module-hangs/26912/2 "2018-03-06T18:06:14Z")

</div>

Probably due to an unexpected output? Also you might want to try the  
telnet module to communicate directly.

---

<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:** [March 6, 2018, 7:19pm UTC](https://forum.ansible.com/t/expect-module-hangs/26912/3 "2018-03-06T19:19:30Z")

</div>

It looks like you are trying with levels of responses, that is not supported.  
prompt bellow is also called question as in the documentation.

- expect:  
&nbsp;&nbsp;&nbsp;&nbsp;command: tel...  
&nbsp;&nbsp;&nbsp;&nbsp;responses:  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;prompt-1: answer-1  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;prompt-2: answer-2  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;prompt-3:  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;- answer-3  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;- answer-4  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;prompt-4:  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;- anser-5

When an prompt appears more than once you need a list of answers like prompt-3 about, the first time it sees prompt-3 expect will respond with answer-3, the nest time it sees prompt-3 it will respond with answer-4.  
The prompt/question is regex, so all regex special character like ()? need to be escaped if you have those character in that in the prompt.

It you don't get it working with this you need to provide the complete output when you do this manually.

---

<div class="post-metadata">

**Author:** ![DOkuwa](https://sea1.discourse-cdn.com/ansible/user_avatar/forum.ansible.com/dokuwa/32/1471_2.png) [@DOkuwa](https://forum.ansible.com/u/DOkuwa)\
**Post date:** [March 7, 2018, 10:26am UTC](https://forum.ansible.com/t/expect-module-hangs/26912/4 "2018-03-07T10:26:32Z")

</div>

thanks

when I run this I also get error message after amending the yaml script

---

<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:** [March 7, 2018, 11:38am UTC](https://forum.ansible.com/t/expect-module-hangs/26912/5 "2018-03-07T11:38:40Z")

</div>

You can only have one command: in expect.

If command is a prompt its not correctly indented.  
And one prompt can only be listed once, the different responses is a list to that prompt.

If you would like more help you \_need\_ to provide the complete output when you do this task manually, without it this is futile.

---

<div class="post-metadata">

**Author:** ![DOkuwa](https://sea1.discourse-cdn.com/ansible/user_avatar/forum.ansible.com/dokuwa/32/1471_2.png) [@DOkuwa](https://forum.ansible.com/u/DOkuwa)\
**Post date:** [March 7, 2018, 11:40am UTC](https://forum.ansible.com/t/expect-module-hangs/26912/6 "2018-03-07T11:40:19Z")

</div>

Hi,

I have just done this manually on the switch and it worked

User Access Verification  
Username: admin  
Password:  
POD2\_C3560#copy running-config ftp:  
Address or name of remote host ? 10.241.11.237  
Destination filename [pod2\_c3560-confg]?  
Writing pod2\_c3560-confg !!  
8063 bytes copied in 1.108 secs (7277 bytes/sec)  
POD2\_C3560#

Thanks

---

<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:** [March 7, 2018, 12:33pm UTC](https://forum.ansible.com/t/expect-module-hangs/26912/7 "2018-03-07T12:33:56Z")

</div>

I think you forgot the exit at the end, so I included it.

&nbsp;&nbsp;&nbsp;- name: run show command via Telnet using the expect module  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;expect:  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;command: telnet 10.101.250.12  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;responses:  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Username: admin  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Password: xxxxx  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;POD2\_C3560#:  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;- copy running-config ftp  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;- exit  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Address or name of remote host \[\]\?: 10.241.11.237  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Destination filename \[.\*\]\?: ''

The '' is the same as just pressing enter.  
I have escaped ? with backslash since they are character with meaning in regex.  
Since the prompt POD2\_C3560# comes up two times this is a list with the responses.

---

<div class="post-metadata">

**Author:** ![DOkuwa](https://sea1.discourse-cdn.com/ansible/user_avatar/forum.ansible.com/dokuwa/32/1471_2.png) [@DOkuwa](https://forum.ansible.com/u/DOkuwa)\
**Post date:** [March 7, 2018, 5:40pm UTC](https://forum.ansible.com/t/expect-module-hangs/26912/8 "2018-03-07T17:40:57Z")

</div>

Hi,

A big thanks you it worked

Very Much appreciated
