2

I'm trying to create a playbook for installation of tableau server. but there is a part where it needs a response.

Here is my code:

- name: Apply Changes
  expect:
    command: /opt/tableau/tableau_server/packages/customer-bin.10500.19.0313.1245/tsm pending-changes apply -u ansible -p ansible
    responses:
      'This operation will perform a server restart. Are you sure you wish to continue?(y/n):': 'y'
    timeout: 600
    echo: yes
  tags:
    - start

but I have an error

atal: [tableau3.server.com]: FAILED! => {
    "changed": true, 
    "cmd": "/opt/tableau/tableau_server/packages/customer-bin.10500.19.0313.1245/tsm pending-changes apply -u ansible -p ansible", 
    "delta": "0:10:00.223831", 
    "end": "2019-05-05 21:16:46.914799", 
    "invocation": {
        "module_args": {
            "chdir": null, 
            "command": "/opt/tableau/tableau_server/packages/customer-bin.10500.19.0313.1245/tsm pending-changes apply -u ansible -p ansible", 
            "creates": null, 
            "echo": true, 
            "removes": null, 
            "responses": {
                "This operation will perform a server restart. Are you sure you wish to continue?(y/n):": "y"
            }, 
            "timeout": 600
        }
    }, 
    "msg": "non-zero return code", 
    "rc": 129, 
    "start": "2019-05-05 21:06:46.690968", 
    "stdout": "This operation will perform a server restart. Are you sure you wish to continue?\r\n(y/n): ", 
    "stdout_lines": [
        "This operation will perform a server restart. Are you sure you wish to continue?", 
        "(y/n): "
    ]
}
pynexj
  • 19,215
  • 5
  • 38
  • 56
  • Check this https://stackoverflow.com/questions/38393343/how-to-use-ansible-expect-module-for-multiple-different-responses – Raghuram May 06 '19 at 05:34

1 Answers1

4

The command responds with 2 lines

stdout_lines": [
    "This operation will perform a server restart. Are you sure you wish to continue?", 
    "(y/n): "

, but the item in responses expects only 1 line.

responses:
  'This operation will perform a server restart. Are you sure you wish to continue?(y/n):': 'y'

Hence, no item in responses fits and the module fails.

The responses are string/regex. Try

responses:
  y/n: 'y'

Notes says:

The expect module is designed for simple scenarios. For more complex needs, consider the use of expect code with the shell or script modules. (An example is part of the shell module documentation)

Vladimir Botka
  • 58,131
  • 4
  • 32
  • 63