# Expect module throwing up an error while passing responses

**URL:** <https://forum.ansible.com/t/expect-module-throwing-up-an-error-while-passing-responses/22282>\
**Category:** Ansible Project\
**Created:** [August 12, 2016, 6:25pm UTC](https://forum.ansible.com/t/expect-module-throwing-up-an-error-while-passing-responses/22282 "2016-08-12T18:25:45Z")\
**Posts on this page:** 15\
**Page:** 1

<div class="post-metadata">

**Author:** ![challa.tek](https://avatars.discourse-cdn.com/v4/letter/c/b38774/32.png) [@challa.tek](https://forum.ansible.com/u/challa.tek)\
**Post date:** [August 12, 2016, 6:25pm UTC](https://forum.ansible.com/t/expect-module-throwing-up-an-error-while-passing-responses/22282/1 "2016-08-12T18:25:45Z")

</div>

My play is like:

- name: configuring pdf harmony  
expect:  
command: ./install.sh  
responses:  
‘This will install pdfharmony on your system. Do you want to continue[y/N]?’: y  
‘Do you agree with this copyright? [y/N]’: y  
‘Now you must enter a valid registration number:’: XXXX-XXXX-XXXX-XXXX-XXXX  
echo: yes  
args:  
chdir: ‘{{ dest\_dir }}/pdfHarmony\_20\_L26\_64’  
become: yes

error when running this play:

{“changed”: true, “cmd”: “./install.sh”, “delta”: “0:00:30.186764”, “end”: “2016-08-12 14:02:23.384237”, “failed”: true, “invocation”: {“module\_args”: {“chdir”: “/usr/local/pdfHarmony\_20\_L26\_64”, “command”: “./install.sh”, “creates”: null, “echo”: true, “removes”: null, “responses”: {“Do you agree with this copyright? [y/N]”: “y”, “Now you must enter a valid registration number:”: “XXXX-XXXX-XXXX-XXXX-XXX”, “This will install pdfharmony on your system. Do you want to continue[y/N]?”: “y”}, “timeout”: 30}, “module\_name”: “expect”}, “rc”: 1, “start”: “2016-08-12 14:01:53.197473”, “stdout”: “This will install pdfharmony on your system. Do you want to continue[y/N]? : y\r\n\u001b[H\u001b[2JWelcome to the Appligent pdfharmony installer.\r\n\r\nAPPLIGENT INC d/b/a Appligent Document Solutions\r\n\r\nServer Software License Agreement\r\n\r\nPlease read this license carefully before using this software. By using any \r\nportion of this software, you accept all terms and conditions of this agreement.\r\nIf you do not agree with the terms of this license agreement, do not use this \r\nsoftware. Promptly return this software UNOPENED along with the rest of the \r\npackage and proof of payment, to the location from which you obtained it for a \r\nfull refund.\r\n\r\nThis License allows you to use ONE copy of the enclosed software ("Software") \r\non a SINGLE Server of up to four (4) cores or on a single server with more than \r\nfour (4) cores as detailed in the Purchase Agreement. You may make one backup \r\ncopy of the Software for disaster recovery purposes, provided your backup is not\r\ninstalled or used on any computer. You may not run the Software over a Network \r\nfrom a mounted or mapped drive. You may not copy the software to use for \r\ndevelopment, testing or staging purposes.\r\n\r\n1. Restrictions: You may not resell, transfer, rent or lease the Software \r\nwithout the specific agreement of Appligent. You may not reverse engineer, \r\n\u001b[7m–More–\u001b[27m”, “stdout\_lines”: [“This will install pdfharmony on your system. Do you want to continue[y/N]? : y”, “\u001b[H\u001b[2JWelcome to the Appligent pdfharmony installer.”, “”, “APPLIGENT INC d/b/a Appligent Document Solutions”, “”, “Server Software License Agreement”, “”, "Please read this license carefully before using this software. By using any ", “portion of this software, you accept all terms and conditions of this agreement.”, "If you do not agree with the terms of this license agreement, do not use this ", "software. Promptly return this software UNOPENED along with the rest of the ", "package and proof of payment, to the location from which you obtained it for a ", “full refund.”, “”, "This License allows you to use ONE copy of the enclosed software ("Software") ", "on a SINGLE Server of up to four (4) cores or on a single server with more than ", "four (4) cores as detailed in the Purchase Agreement. You may make one backup ", “copy of the Software for disaster recovery purposes, provided your backup is not”, "installed or used on any computer. You may not run the Software over a Network ", "from a mounted or mapped drive. You may not copy the software to use for ", “development, testing or staging purposes.”, “”, "1. Restrictions: You may not resell, transfer, rent or lease the Software ", "without the specific agreement of Appligent. You may not reverse engineer, ", “\u001b[7m–More–\u001b[27m”]}

when installing manually,  
Here when you pass y to the first prompt, you get a copyright agreement which is more than a page and you will find --More-- at the end of the page and when keep on pressing enter last line of the agreement the second prompt(question appears) like

[![](https://lh3.googleusercontent.com/-VcmdTELGCHw/V64UTztsq_I/AAAAAAAAAEg/8FaEIxz3UgE5G0weMQHTB3nRMOnlTrujwCLcB/s400/pdf.PNG)](https://lh3.googleusercontent.com/-VcmdTELGCHw/V64UTztsq_I/AAAAAAAAAEg/8FaEIxz3UgE5G0weMQHTB3nRMOnlTrujwCLcB/s1600/pdf.PNG)

when you keep pressing enter it comes to

[![](https://lh3.googleusercontent.com/-zQGiuZ2ayfw/V64Uh-67GnI/AAAAAAAAAEk/1JZNpIJoONsj39_Lp39sI-15sAJPjZqIQCLcB/s320/last.PNG)](https://lh3.googleusercontent.com/-zQGiuZ2ayfw/V64Uh-67GnI/AAAAAAAAAEk/1JZNpIJoONsj39_Lp39sI-15sAJPjZqIQCLcB/s1600/last.PNG)

What is the exact problem i am not able to understand

---

<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:** [August 12, 2016, 7:59pm UTC](https://forum.ansible.com/t/expect-module-throwing-up-an-error-while-passing-responses/22282/2 "2016-08-12T19:59:34Z")

</div>

> My play is like:
> 
> - name: configuring pdf harmony  
> &nbsp;&nbsp;expect:  
> &nbsp;&nbsp;&nbsp;command: ./install.sh  
> &nbsp;&nbsp;&nbsp;responses:  
> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;'This will install pdfharmony on your system. Do you want to continue[y/N]?': y  
> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;'Do you agree with this copyright? [y/N]': y  
> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;'Now you must enter a valid registration number:': XXXX-XXXX-XXXX-XXXX-XXXX  
> &nbsp;&nbsp;&nbsp;echo: yes  
> &nbsp;&nbsp;args:  
> &nbsp;&nbsp;&nbsp;chdir: '{{ dest\_dir }}/pdfHarmony\_20\_L26\_64'  
> &nbsp;&nbsp;become: yes
> 
> error when running this play:

\<snip\>

> "without the specific agreement of Appligent. You may not reverse engineer,  
> ", "\u001b[7m--More--\u001b[27m"]}

It's stops and wait at "--More--"

> when installing manually,  
> Here when you pass y to the first prompt, you get a copyright agreement  
> which is more than a page and you will find --More-- at the end of the page  
> and when keep on pressing enter last line of the agreement the second  
> prompt(question appears) like
> 
> What is the exact problem i am not able to understand

You need to handle the "--More--" in expect, but your responses doesn't.  
Add something like this  
&nbsp;&nbsp;&nbsp;&nbsp;'--More--': \r

---

<div class="post-metadata">

**Author:** ![challa.tek](https://avatars.discourse-cdn.com/v4/letter/c/b38774/32.png) [@challa.tek](https://forum.ansible.com/u/challa.tek)\
**Post date:** [August 12, 2016, 8:22pm UTC](https://forum.ansible.com/t/expect-module-throwing-up-an-error-while-passing-responses/22282/3 "2016-08-12T20:22:30Z")

</div>

Hi,

Thanks for your reply, but when i pass ‘–More–’: \r . it is failing at

“\u001b[7m–More–\u001b[27m\u0007\u0007”, “Updates may be licensed to you by Appligent with additional or different terms.”, “”, "Do you agree with this copyright? [y/N] : "]}

it is like not listening to my next response after more… i am not able to understand how this is happening

it is not taking my response for

‘Do you agree with this copyright? [y/N]’: y

i have added more and now it looks like

- name: configuring pdf harmony

expect:

command: ./install.sh

responses:

‘This will install pdfharmony on your system. Do you want to continue[y/N]?’: y

‘–More–’: \r

‘(?i)Do you agree with this copyright? [y/N]’: y

‘Now you must enter a valid registration number’: XXXX-XXXX-XXXX-XXXX-XXXX

echo: yes

args:

chdir: ‘{{ dest\_dir }}/pdfHarmony\_20\_L26\_64’

become: yes

---

<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:** [August 12, 2016, 9:01pm UTC](https://forum.ansible.com/t/expect-module-throwing-up-an-error-while-passing-responses/22282/4 "2016-08-12T21:01:56Z")

</div>

That because are regexp expression, since you mean literary you need to escape them like this.  
'Do you agree with this copyright? \[y/N\]': y

---

<div class="post-metadata">

**Author:** ![challa.tek](https://avatars.discourse-cdn.com/v4/letter/c/b38774/32.png) [@challa.tek](https://forum.ansible.com/u/challa.tek)\
**Post date:** [August 12, 2016, 9:20pm UTC](https://forum.ansible.com/t/expect-module-throwing-up-an-error-while-passing-responses/22282/5 "2016-08-12T21:20:17Z")

</div>

thanks, for your suggestion  
i have changed that line but still getting the same error  
is there a different way of approach for this problem i am not able to figure out

---

<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:** [August 12, 2016, 9:30pm UTC](https://forum.ansible.com/t/expect-module-throwing-up-an-error-while-passing-responses/22282/6 "2016-08-12T21:30:54Z")

</div>

The question mark is also a special character so you need to escape that one also. But then is should work since all the regexp characters is escaped.

---

<div class="post-metadata">

**Author:** ![challa.tek](https://avatars.discourse-cdn.com/v4/letter/c/b38774/32.png) [@challa.tek](https://forum.ansible.com/u/challa.tek)\
**Post date:** [August 15, 2016, 1:07pm UTC](https://forum.ansible.com/t/expect-module-throwing-up-an-error-while-passing-responses/22282/7 "2016-08-15T13:07:35Z")

</div>

Thank you very much kai for your help.  
your suggestion worked after i escaped the question mark.

---

<div class="post-metadata">

**Author:** ![Murthy\_Vipparthy](https://avatars.discourse-cdn.com/v4/letter/m/7cd45c/32.png) [@Murthy\_Vipparthy](https://forum.ansible.com/u/Murthy_Vipparthy)\
**Post date:** [May 25, 2017, 8:22pm UTC](https://forum.ansible.com/t/expect-module-throwing-up-an-error-while-passing-responses/22282/8 "2017-05-25T20:22:39Z")

</div>

**Kai**

Here is my playbook command

# ansible-playbook opencl.yml --ask-become-pass -vvvv

When I use my Playbook with below option while

responses:  
‘Press [Enter] to continue:’: \n  
‘–More–’ : \r  
‘Do you accept this license?[y/n]’: y

I am being stuck @ Output like below and this is NOT further proceeding for rest of responses

**“”,**  
**“Press [Enter] to continue:”,**  
**“”,**  
**"Do you accept this license? [y/n]: "**  
**]**  
**}**

**Any help on this**

**Thank you**

**-Murthy**

---

<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:** [May 26, 2017, 5:56pm UTC](https://forum.ansible.com/t/expect-module-throwing-up-an-error-while-passing-responses/22282/9 "2017-05-26T17:56:38Z")

</div>

According to your output you are missing a space between the question mark and the square bracket in your responses.

---

<div class="post-metadata">

**Author:** ![Murthy\_Vipparthy](https://avatars.discourse-cdn.com/v4/letter/m/7cd45c/32.png) [@Murthy\_Vipparthy](https://forum.ansible.com/u/Murthy_Vipparthy)\
**Post date:** [May 26, 2017, 7:44pm UTC](https://forum.ansible.com/t/expect-module-throwing-up-an-error-while-passing-responses/22282/10 "2017-05-26T19:44:36Z")

</div>

**Thank you Kai for response. Unfortunately this did NOT work. Let me explain this scenario once again.**

**Here is Complete expect Module Code.**

- name: Perform auto prompt for **responses**  
expect:  
chdir: /tools/murthy/AOCL-SDK-16.0  
command: /bin/bash setup\_pro.sh  
responses:  
‘Press [Enter] to continue:’: \n  
‘–More–’ : \r

timeout: 180  
echo: yes

- name: Perform auto prompt for **responses2**  
expect:  
chdir: /tools/murthy/AOCL-SDK-16.0  
command: /bin/bash setup\_pro.sh  
responses:  
‘Do you accept this license? [y/n]’: y\n  
echo: yes

**Here is Error and final OUT PUT @ below, Can you explain whether first expect module being executed ?? I am suspecting this command NOT being executed and timeout happening. When I run manually from terminal, I need to press [Enter] command @ least 20 times and works OK. but when I use this expect module, I am NOT able GET this work. I have also separated two responses also for easy debugging.**

fatal: [10.10.10.147]: FAILED! =\> {  
“changed”: true,  
“cmd”: “/bin/bash setup\_pro.sh”,  
“delta”: “0:03:07.381255”,  
“end”: “2017-05-26 12:21:14.170676”,  
“failed”: true,  
“invocation”: {  
“module\_args”: {  
“chdir”: “/tools/murthy/AOCL-SDK-16.0”,  
“command”: “/bin/bash setup\_pro.sh”,  
“creates”: null,  
“echo”: true,  
“removes”: null,  
“responses”: {  
“–More–”: “\r”,  
“Press \[Enter\] to continue:”: “\n”  
},  
“timeout”: 180  
}  
},  
“msg”: “command exceeded timeout”,  
“rc”: null,  
“start”: “2017-05-26 12:18:06.789421”,

Also OUTPUT here

“”,  
“”,  
“Press [Enter] to continue:\n”,  
“”,  
“”,  
"Do you accept this license? [y/n]: "  
]  
}

---

<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:** [May 28, 2017, 5:34pm UTC](https://forum.ansible.com/t/expect-module-throwing-up-an-error-while-passing-responses/22282/11 "2017-05-28T17:34:57Z")

</div>

You can't split the task in two, now the first task is waiting for a response on "Do you accept this license? [y/n]:", but since your first task doesn't contain that. It hang until the timeout and you get a failed task and the play aborts.

---

<div class="post-metadata">

**Author:** ![Murthy\_Vipparthy](https://avatars.discourse-cdn.com/v4/letter/m/7cd45c/32.png) [@Murthy\_Vipparthy](https://forum.ansible.com/u/Murthy_Vipparthy)\
**Post date:** [May 30, 2017, 8:47pm UTC](https://forum.ansible.com/t/expect-module-throwing-up-an-error-while-passing-responses/22282/12 "2017-05-30T20:47:27Z")

</div>

Hi Kai,

I was able to combine both tasks like below and able to work OUT.

**responses:**  
**‘Press [Enter] to continue:’: \n\r**  
**‘–More–’ : \r**  
**‘Do you accept this license? [y/n]’: y**

During my further installation, I got another error that script is looking for absolute path. Do you know how to avoid absolute path prompt ??

-Murthy

---

<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:** [June 1, 2017, 3:46pm UTC](https://forum.ansible.com/t/expect-module-throwing-up-an-error-while-passing-responses/22282/13 "2017-06-01T15:46:09Z")

</div>

All the questions the script ask you'll to add it to your responses in expect.

---

<div class="post-metadata">

**Author:** ![Lavanya\_VJ](https://avatars.discourse-cdn.com/v4/letter/l/73ab20/32.png) [@Lavanya\_VJ](https://forum.ansible.com/u/Lavanya_VJ)\
**Post date:** [April 13, 2023, 1:42pm UTC](https://forum.ansible.com/t/expect-module-throwing-up-an-error-while-passing-responses/22282/14 "2023-04-13T13:42:36Z")

</div>

Hi all,

i am facing the issues with expect module though the timeout: 600 is mentioned, i always get “msg”: “command exceeded timeout”, i have around 25 reponses to answer.

- name: install file  
expect:  
command: /tmp/install.run  
responses:  
‘Installation path? [/tmp/output]:’: ‘/tmp/output/new’  
‘Run after installation? [yes]:’: ‘yes’  
timeout: 600

---

<div class="post-metadata">

**Author:** ![Lavanya\_VJ](https://avatars.discourse-cdn.com/v4/letter/l/73ab20/32.png) [@Lavanya\_VJ](https://forum.ansible.com/u/Lavanya_VJ)\
**Post date:** [April 13, 2023, 2:01pm UTC](https://forum.ansible.com/t/expect-module-throwing-up-an-error-while-passing-responses/22282/15 "2023-04-13T14:01:10Z")

</div>

I think i need to hit enter after each responses how is that possible because i see the ansible output fails

“Please enter installation path ':”,  
“”,  
"Installation path?\u001b[0m [/tmp/output\]: "
