Ansible Expect Respones query

Hi all,

I’m trying to install Talend ESB 6.3.1 using Ansible. This works up to a point.

The last few steps are causing me the grief.

Once TESB has been installed there are manual steps to complete the installation as below. I have tried using expect/responses/

  • name: start talend ESB trun
    become: yes
    become_user: ‘{{ talend_user }}’
    expect:
    command: /bin/sh {{ talend_software_dir }}/{{ talend_esb_dir }}/esb/container/bin/trun
    timeout: 240
    responses:
    Question:
  • ‘feature:install war’
  • ‘feature:install wrapper’
  • ‘wrapper:install -s AUTO_START -n TALEND-ESB-CONTAINER -d Talend-ESB-Container -D “Talend ESB Container Service”’

Error thrown
TASK [start talend ESB trun] ***********************************************************************************************************************************
fatal: [10.138.52.101]: FAILED! => {“changed”: true, “cmd”: “/bin/sh /data/talend/talendesb/esb/container/bin/trun”, “delta”: “0:04:00.561246”, “end”: “2017-09-14 09:37:57.722055”, “failed”: true, “msg”: “command exceeded timeout”, “rc”: null, “start”: “2017-09-14 09:33:57.160809”, “stdout”: “trun: JAVA_HOME not set; results may vary\r\n\u001b[33m ______ __ __ \u001b[0m\r\n\u001b[33m /_ / / /_ ___ / / \u001b[0m\r\n\u001b[33m / / / _ / / -_) _ \\/ _ / \u001b[0m\r\n\u001b[33m /_/ \\_,_/_/\\__/_//_/\\_,_/ \u001b[0m\r\n (version 6.3.1) \r\n\r\nHit '\u001b[1m<tab>\u001b[0m' for a list of available commands\r\nand '\u001b[1m[cmd] --help\u001b[0m' for help on a specific command.\r\nHit '\u001b[1m<ctrl-d>\u001b[0m' or '\u001b[1msystem:shutdown\u001b[0m' to shutdown the TRUN.\r\n\r\n\u001b[1mkaraf\u001b[0m@trun()> ", "stdout_lines": ["trun: JAVA_HOME not set; results may vary", "\u001b[33m ______ __ __ \u001b[0m", "\u001b[33m /_ __/__ _/ /__ ___ ___/ / \u001b[0m", "\u001b[33m / / / _ / / -) _ \/ _ / \u001b[0m", "\u001b[33m // \,//\__////\,/ \u001b[0m”, " (version 6.3.1) ", “”, “Hit ‘\u001b[1m\u001b[0m’ for a list of available commands”, “and ‘\u001b[1m[cmd] --help\u001b[0m’ for help on a specific command.”, “Hit ‘\u001b[1m\u001b[0m’ or ‘\u001b[1msystem:shutdown\u001b[0m’ to shutdown the TRUN.”, “”, "\u001b[1mkaraf\u001b[0m@trun()> "]}
to retry, use: --limit @/home/pbirksmith/Workspace/app-automation/talend_esb_install.retry

To run these steps manually I need to follow the following

  1. Run trun command

/bin/sh /data/talend/talendesb/esb/container/bin/trun

This starts up a shell as below
[talenduser@talend-jobserver-1 bin]$ /bin/sh /data/talend/talendesb/esb/container/bin/trun
trun: JAVA_HOME not set; results may vary


/_ / / /_ ___ / /
/ / / _ `/ / -
) _ / _ /
/
/ _,
//_////_,_/
(version 6.3.1)

Hit ‘’ for a list of available commands
and ‘[cmd] --help’ for help on a specific command.
Hit ‘’ or ‘system:shutdown’ to shutdown the TRUN.

karaf@trun()>

At this point I need to run commands that install specific features and services

E.g.
karaf@trun()> feature:install war
karaf@trun()> feature:install wrapper
karaf@trun()> feature:install webconsole
karaf@trun()> wrapper:install -s AUTO_START -n TALEND-ESB-CONTAINER -d Talend-ESB-Container -D “Talend ESB Container Service”
Creating file: /data/talend/talendesb/esb/container/bin/TALEND-ESB-CONTAINER-wrapper
Creating file: /data/talend/talendesb/esb/container/bin/TALEND-ESB-CONTAINER-service
Creating file: /data/talend/talendesb/esb/container/bin/TALEND-ESB-CONTAINER.service
Creating file: /data/talend/talendesb/esb/container/etc/TALEND-ESB-CONTAINER-wrapper.conf
Creating missing directory: /data/talend/talendesb/esb/container/lib/wrapper
Creating file: /data/talend/talendesb/esb/container/lib/wrapper/libwrapper.so
Creating file: /data/talend/talendesb/esb/container/lib/wrapper/karaf-wrapper.jar
Creating file: /data/talend/talendesb/esb/container/lib/wrapper/karaf-wrapper-main.jar

Setup complete. You may wish to tweak the JVM properties in the wrapper configuration file:
/data/talend/talendesb/esb/container/etc/TALEND-ESB-CONTAINER-wrapper.conf
before installing and starting the service.

RedHat/Fedora/CentOS Linux system detected (SystemV):
To install the service:
$ ln -s /data/talend/talendesb/esb/container/bin/TALEND-ESB-CONTAINER-service /etc/init.d/
$ chkconfig TALEND-ESB-CONTAINER-service --add

To start the service when the machine is rebooted:
$ chkconfig TALEND-ESB-CONTAINER-service on

To disable starting the service when the machine is rebooted:
$ chkconfig TALEND-ESB-CONTAINER-service off

To start the service:
$ service TALEND-ESB-CONTAINER-service start

To stop the service:
$ service TALEND-ESB-CONTAINER-service stop

To uninstall the service :
$ chkconfig TALEND-ESB-CONTAINER-service --del
$ rm /etc/init.d/TALEND-ESB-CONTAINER-service

Any help on this would be greatly appreciated.
Cheers

Peter Birksmith

I'm trying to install Talend ESB 6.3.1 using Ansible. This works up to a
point.

The last few steps are causing me the grief.

Once TESB has been installed there are manual steps to complete the
installation as below. I have tried using expect/responses/

    - name: start talend ESB trun
      become: yes
      become_user: '{{ talend_user }}'
      expect:
        command: /bin/sh {{ talend_software_dir }}/{{ talend_esb_dir
}}/esb/container/bin/trun
        timeout: 240
        responses:
          Question:
            - 'feature:install war'
            - 'feature:install wrapper'
            - 'wrapper:install -s AUTO_START -n TALEND-ESB-CONTAINER -d
Talend-ESB-Container -D "Talend ESB Container Service"'

I see you have used the example in the documentation.
With Question it means, what string is expect going to trigger on, think of it as question/answer.

One question can have many answers, the first time is sees the question it will answer with the first one, second time it sees the question the second answer and so on.

Hit '<tab>' for a list of available commands
and '[cmd] --help' for help on a specific command.
Hit '<ctrl-d>' or 'system:shutdown' to shutdown the TRUN.

karaf@trun()>

At this point I need to run commands that install specific features and
services

E.g.
karaf@trun()> feature:install war
karaf@trun()> feature:install wrapper
karaf@trun()> feature:install webconsole
karaf@trun()> wrapper:install -s AUTO_START -n TALEND-ESB-CONTAINER -d

So in this scenario your question will be the prompt, it's important that the question is unique so it doesn't trigger the answer before it should.

To me is seams that the string "()>" in the prompt doesn't appear other than in the prompt so you can use that one.
Question part of expect is regexp so you need to escape regexp special characters like ()

So if you try this it should work

   responses:
     \(\)>:
       - 'feature:install war'
       - 'feature:install wrapper'
       ...

Hi Kai

Thanks that moved the process further than before. Now I believe I’m getting a false positive response. The response below is really a successful response from Talend…however, Ansible has treated it as fatal.
I’ve checked that everything supposed to be installed has been installed. I think maybe it is because there are no further questions to answer and it needs to be escaped so that the script moves on.

TASK [start talend ESB trun] **********************************************************************************************************************
fatal: [10.138.52.101]: FAILED! => {“changed”: false, “failed”: true, “msg”: “No remaining responses for ‘\(\)>’, output was ’ wrapper:install -s AUTO_START -n TALEND-ESB-CONTAINER -d Talend-ES \rB-Container -D "Talend ESB Container Service"\r\r\nCreating file: \u001b[1m/data/talend/talendesb/esb/container/bin/TALEND-ESB-CONTAINER-wrapper\u001b[m\r\nCreating file: \u001b[1m/data/talend/talendesb/esb/container/bin/TALEND-ESB-CONTAINER-service\u001b[m\r\nCreating file: \u001b[1m/data/talend/talendesb/esb/container/bin/TALEND-ESB-CONTAINER.service\u001b[m\r\nCreating file: \u001b[1m/data/talend/talendesb/esb/container/etc/TALEND-ESB-CONTAINER-wrapper.conf\u001b[m\r\nCreating missing directory: \u001b[1m/data/talend/talendesb/esb/container/lib/wrapper\u001b[m\r\nCreating file: \u001b[1m/data/talend/talendesb/esb/container/lib/wrapper/libwrapper.so\u001b[m\r\nCreating file: \u001b[1m/data/talend/talendesb/esb/container/lib/wrapper/karaf-wrapper.jar\u001b[m\r\nCreating file: \u001b[1m/data/talend/talendesb/esb/container/lib/wrapper/karaf-wrapper-main.jar\u001b[m\r\n\r\nSetup complete. You may wish to tweak the JVM properties in the wrapper configuration file:\r\n\t/data/talend/talendesb/esb/container/etc/TALEND-ESB-CONTAINER-wrapper.conf\r\nbefore installing and starting the service.\r\n\r\n\r\n\u001b[1mRedHat/Fedora/CentOS Linux system detected (SystemV):\u001b[22m\r\n To install the service:\r\n $ ln -s /data/talend/talendesb/esb/container/bin/TALEND-ESB-CONTAINER-service /etc/init.d/\r\n $ chkconfig TALEND-ESB-CONTAINER-service --add\r\n\r\n To start the service when the machine is rebooted:\r\n $ chkconfig TALEND-ESB-CONTAINER-service on\r\n\r\n To disable starting the service when the machine is rebooted:\r\n $ chkconfig TALEND-ESB-CONTAINER-service off\r\n\r\n To start the service:\r\n $ service TALEND-ESB-CONTAINER-service start\r\n\r\n To stop the service:\r\n $ service TALEND-ESB-CONTAINER-service stop\r\n\r\n To uninstall the service :\r\n $ chkconfig TALEND-ESB-CONTAINER-service --del\r\n $ rm /etc/init.d/TALEND-ESB-CONTAINER-service\r\n\r\n\u001b[1mFor systemd compliant Linux: \u001b[22m\r\n To install the service (and enable at system boot):\r\n $ systemctl enable /data/talend/talendesb/esb/container/bin/TALEND-ESB-CONTAINER.service\r\n\r\n To start the service:\r\n $ systemctl start TALEND-ESB-CONTAINER\r\n\r\n To stop the service:\r\n $ systemctl stop TALEND-ESB-CONTAINER\r\n\r\n To check the current service status:\r\n $ systemctl status TALEND-ESB-CONTAINER\r\n\r\n To see service activity journal:\r\n $ journalctl -u TALEND-ESB-CONTAINER\r\n\r\n To uninstall the service (and disable at system boot):\r\n $ systemctl disable TALEND-ESB-CONTAINER\r\n\u001b[1mkaraf\u001b[0m@trun()>'”}

Thanks again. This has really help clarify this module for me as well.

Cheers
Peter

Hi Kai

Thanks that moved the process further than before. Now I believe I'm
getting a false positive response. The response below is really a
successful response from Talend...however, Ansible has treated it as fatal.

In your output below the last output is the prompt, and since expect sees that it try to answer but have run out of responses.

I've checked that everything supposed to be installed has been installed.
I think maybe it is because there are no further questions to answer and it
needs to be escaped so that the script moves on.

When you run the command manually I guess you need to type in exit/quit or something to exit from the command?
If so, this need to be part of the responses so expect exit gracefully.

journalctl -u TALEND-ESB-CONTAINER\r\n\r\n To uninstall the service (and
disable at system boot):\r\n $ systemctl disable
TALEND-ESB-CONTAINER\r\n\u001b[1mkaraf\u001b[0m@trun()>'"}

The last thing expect sees "@trun()>".