Expect module throwing up an error while passing responses

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

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

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

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

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.

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

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.

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]: "
]
}

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.

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

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

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

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\ ]: "