Ansible - Responding to prompts

Does anyone know how to read back a prompt to a control server from a remote host? say if an installation fails and prompts for a retry or continue, this prompt can be responded to from the control server. Is this possible?

Only way to deal with interactivity is to use the expect module.

I have an installation process that is trying to create a ton of database tables that have already been created, my goal is to respond ‘continue’ from the control server when a failure occurs for creating such tables to allow the install continue.

From my research it appears the expect module would work perfectly for
hard-coded responses to questions that I already have knowledge of... as
Ansible is basically an automated replay of an otherwise manual process
including recorded prompts and responses. Outside of such scenarios where i
do not already know of prompts to expect, is there a way to read back in
real time, prompts to the control server for a response call back to the
remote host?

Ansible have no such feature.

I have an installation process that is trying to create a ton of database
tables that have already been created, my goal is to respond 'continue'
from the control server when a failure occurs for creating such tables to
allow the install continue.

If this is a prompt that have something in common or it's possible to create a regexp for you can still use expect.
Lets say the text every time is "Table exist, type continue to continue", then the expect responses looks like this

responses:
  Table exist, type continue to continue:
    - continue
    - continue
    - continue
    ...

The number of continue don't need to be exact it will work as long as you have the correct amount or more.
So if you only think you get about 20 of this prompt just add 40 of them an it will work.

An other option if you have access to the script/program creating the tables, is to use "create table if not exist" since most databases support this kind of feature.

Hi Olstad,

I have been able to setup python3 using anaconda on my control and remote hosts so that i can utilize the pexpect>3.3 which is a requirement for using the Ansible expect module. So this is what I have come up with:

  • name: Installing Products
    expect:
    echo: yes
    chdir: “{{ LOC_PKG }}/is-suite/”
    command: ./setup -rsp {{ LOC_PKG }}/is-suite/{{ RESONSE_FILE_1171_INFO }} -force -verbose
    timeout: null
    responses:
    (.)Error Executing SQL statement\nCREATE TABLE xmeta(>): “2”

As opposed to the previous task i had:

  • name: Installing Products
    shell: ./setup -rsp {{ LOC_PKG }}/is-suite/{{ RESONSE_FILE_1171_INFO }} -force -verbose
    args:
    chdir: “{{ LOC_PKG }}/is-suite/”

However, I am finding that my setup is executing painfully slow while using the expect module to run my setup. I looked at some forums online and some suggested adjusting the setting pipelining = True in ansible.cfg but this has not made any difference for me. Do you happen to know why this might be happening?

Fist of (.*) is useless with expect, so just remove it.
The dot means any character and the * means 0 or more, so this will always be true.

For (>*) (zero or more greater than) you don't need that one either.
Reason is that expect will trigger on the string without > anyway.

Zero and more quantifier doesn't add anything at the start or the end of a string other that more CPU usage.

Is these two changes going to affect speed in any way I don't know, you'll have to try and see.

You’re right! removing (.) and (>) solved the performance issue! but expect failed to respond. Here is the error I’m trying to respond to:

You're right! removing (.*) and (>*) solved the performance issue! but
expect failed to respond. Here is the error I'm trying to respond to:

===========================================================================
Aug 10, 2019 11:28:32 AM com.ibm.is.install.core.SuiteLogger logError
SEVERE: com.ibm.is.install.engine.runtime.InstallEngine
com.ibm.is.install.exception.InstallException: CDIIN3231E: Error Executing
SQL statement
CREATE TABLE xmeta.COGNITIVE_USER_PREF
(
USERNAME VARGRAPHIC(64) NOT NULL,
COMPONENT VARGRAPHIC(32) NOT NULL,
CATEGORY VARGRAPHIC(64) NOT NULL,
RID VARGRAPHIC(64) NOT NULL,
NAME VARGRAPHIC(64) NOT NULL,
VALUE VARGRAPHIC(255) NOT NULL
)
         at com.ibm.is.install.core.SQLHelper.executeSql(SQLHelper.java:135)
         at com.ibm.is.install.core.SQLHelper.executeFile(SQLHelper.java:214)
         at
com.ibm.is.install.engine.action.builtin.ExecuteSQLAction.execute(ExecuteSQLAction.java:132)
         at
com.ibm.is.install.engine.runtime.InstallEngine.executeAction(InstallEngine.java:1598)
         at
com.ibm.is.install.engine.runtime.InstallEngine.processInstallActionStep(InstallEngine.java:1538)
         at
com.ibm.is.install.engine.runtime.InstallEngine.processActionStep(InstallEngine.java:1422)
         at
com.ibm.is.install.engine.runtime.InstallEngine.processInstallStep(InstallEngine.java:587)
         at
com.ibm.is.install.engine.runtime.InstallEngine.processAllSteps(InstallEngine.java:567)
         at
com.ibm.is.install.engine.runtime.InstallEngine.run(InstallEngine.java:245)
         at
com.ibm.is.install.engine.runtime.InstallEngine.execute(InstallEngine.java:883)
         at com.ibm.is.install.Installer.execute(Installer.java:195)
         at
com.ibm.is.install.AbstractInstaller.recoverAndExecutePlan(AbstractInstaller.java:690)
         at
com.ibm.is.install.AbstractInstaller.execute(AbstractInstaller.java:397)
         at com.ibm.is.install.Installer.main(Installer.java:107)
Caused by: com.ibm.db2.jcc.am.SqlSyntaxErrorException: DB2 SQL Error:
SQLCODE=-601, SQLSTATE=42710, SQLERRMC=XMETA.COGNITIVE_USER_PREF;TABLE,
DRIVER=3.66.46
         at com.ibm.db2.jcc.am.dd.a(dd.java:741)
         at com.ibm.db2.jcc.am.dd.a(dd.java:60)
         at com.ibm.db2.jcc.am.dd.a(dd.java:127)
         at com.ibm.db2.jcc.am.oo.c(oo.java:2763)
         at com.ibm.db2.jcc.am.oo.d(oo.java:2751)
         at com.ibm.db2.jcc.am.oo.b(oo.java:2134)
         at com.ibm.db2.jcc.t4.ab.i(ab.java:226)
         at com.ibm.db2.jcc.t4.ab.c(ab.java:48)
         at com.ibm.db2.jcc.t4.o.b(o.java:38)
         at com.ibm.db2.jcc.t4.tb.h(tb.java:124)
         at com.ibm.db2.jcc.am.oo.hb(oo.java:2129)
         at com.ibm.db2.jcc.am.oo.a(oo.java:3284)
         at com.ibm.db2.jcc.am.oo.e(oo.java:1085)
         at com.ibm.db2.jcc.am.oo.execute(oo.java:1064)
         at com.ibm.is.install.core.SQLHelper.executeSql(SQLHelper.java:124)
         ... 13 more

IBM InfoSphere Information Server encountered the above error.
com.ibm.is.install.exception.InstallException: CDIIN3231E: Error Executing
SQL statement
CREATE TABLE xmeta.COGNITIVE_USER_PREF
(
USERNAME VARGRAPHIC(64) NOT NULL,
COMPONENT VARGRAPHIC(32) NOT NULL,
CATEGORY VARGRAPHIC(64) NOT NULL,
RID VARGRAPHIC(64) NOT NULL,
NAME VARGRAPHIC(64) NOT NULL,
VALUE VARGRAPHIC(255) NOT NULL
)
How would you like to recover from this error?
1. Retry failed action
2. Continue installation
3. Exit installation session
Enter your choice:

I believe that i am using the wrong regex string in expect "Error Executing
SQL statement\nCREATE TABLE xmeta" instead of "How would you like to
recover from this error?"

Actually you should use "Enter your choice", since that is the last string before the program is waiting for an answer.

but im trying to make sure that i am skipping
only CREATE TABLE errors and not just anyone that might need attention.
This is the next thing i need to figure out how to do. I appreciate your
invaluable help so far

It's fragile depending on the other output/error, but I think this should work.

  responses:
    CREATE TABLE xmeta.*Enter your choice: 2

Pexpect has DOTALL on, so a dot includes new lines as a match as well.

I think there’s a limitation to the expect functionality in my process caused by the way the installer works. While the install is in progress i can follow the progress using tail -f <log_file_name> and for reasons unknown to me, when the installer fails, the tail of the log stops at:

I take that back! There was a second question “Do you want to continue the installation process?” that needed to be answered. I added this to my script and it worked as expected. Thanks!