Expect module throwing up an error while passing responses

808 views
Skip to first unread message

chall...@gmail.com

unread,
Aug 12, 2016, 2:25:45 PM8/12/16
to Ansible Project
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

when you keep pressing enter it comes to 


What is the exact problem i am not able to understand


Kai Stian Olstad

unread,
Aug 12, 2016, 4:00:13 PM8/12/16
to ansible...@googlegroups.com
On 12. aug. 2016 20:25, chall...@gmail.com wrote:
> 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:

<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
'--More--': \r

--
Kai Stian Olstad
Message has been deleted

chall...@gmail.com

unread,
Aug 12, 2016, 4:22:30 PM8/12/16
to Ansible Project

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


Kai Stian Olstad

unread,
Aug 12, 2016, 5:02:18 PM8/12/16
to ansible...@googlegroups.com
On 12. aug. 2016 22:19, chall...@gmail.com wrote:
> "\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

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

--
Kai Stian Olstad

chall...@gmail.com

unread,
Aug 12, 2016, 5:20:17 PM8/12/16
to Ansible Project, ansible-pr...@olstad.com
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

Kai Stian Olstad

unread,
Aug 12, 2016, 5:31:04 PM8/12/16
to ansible...@googlegroups.com
On 12. aug. 2016 23:20, chall...@gmail.com wrote:
> 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

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.


--
Kai Stian Olstad

chall...@gmail.com

unread,
Aug 15, 2016, 9:07:35 AM8/15/16
to Ansible Project
Thank you very much kai for your help.
your suggestion worked after i escaped the question mark.


On Friday, August 12, 2016 at 2:25:45 PM UTC-4, chall...@gmail.com wrote:

Murthy Vipparthy

unread,
May 26, 2017, 9:34:01 AM5/26/17
to Ansible Project, ansible-pr...@olstad.com
     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

Kai Stian Olstad

unread,
May 26, 2017, 1:57:02 PM5/26/17
to ansible...@googlegroups.com
On 25. mai 2017 22:22, Murthy Vipparthy wrote:
>
> *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*

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

--
Kai Stian Olstad

Murthy Vipparthy

unread,
May 26, 2017, 3:44:36 PM5/26/17
to Ansible Project, ansible-pr...@olstad.com
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",

Kai Stian Olstad

unread,
May 28, 2017, 1:35:10 PM5/28/17
to ansible...@googlegroups.com
On 26. mai 2017 21:44, Murthy Vipparthy wrote:
> *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.*
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.

--
Kai Stian Olstad

Murthy Vipparthy

unread,
May 30, 2017, 4:47:27 PM5/30/17
to Ansible Project, ansible-pr...@olstad.com

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

Kai Stian Olstad

unread,
Jun 1, 2017, 11:46:40 AM6/1/17
to ansible...@googlegroups.com
On 30. mai 2017 22:47, Murthy Vipparthy wrote:
> During my further installation, I got another error that script is looking
> for absolute path. Do you know how to avoid absolute path prompt ??
All the questions the script ask you'll to add it to your responses in
expect.

--
Kai Stian Olstad

ls440

unread,
Apr 13, 2023, 9:42:36 AM4/13/23
to Ansible Project
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

ls440

unread,
Apr 13, 2023, 10:01:11 AM4/13/23
to Ansible Project
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\  ]: "
Reply all
Reply to author
Forward
0 new messages