How to add key to elastic's kibana-keystore via ansible script?

400 views
Skip to first unread message

Andreas Schampera

unread,
Dec 17, 2019, 5:38:19 AM12/17/19
to Ansible Project
Hi,

I am new to ansible and try to automate the installation process of elastic stack. Currently I am stuck while trying to add a key to kibana's keystore.

Directly from bash (no ansible) the following works:

bash-4.2$ echo bla | /usr/share/kibana/bin/kibana-keystore add test25
Enter value for test25: bla
                        bash-4.2$
The value is taken from stdin.
We can see that the key test25 has been added to keystore.

bash-4.2$ /usr/share/kibana/bin/kibana-keystore list
test25
bash-4.2$


When I try the following in ansible, I get following error:
fatal: [myserver]: FAILED! => {
    "changed": true,
    "cmd": "bash -lc 'echo bla | /usr/share/kibana/bin/kibana-keystore add test26'",
    "delta": "0:00:00.407170",
    "end": "2019-12-17 11:32:36.231715",
    "invocation": {
        "module_args": {
            "_raw_params": "bash -lc 'echo bla | /usr/share/kibana/bin/kibana-keystore add test26'",
            "_uses_shell": true,
            "chdir": null,
            "creates": null,
            "executable": null,
            "removes": null,
            "stdin": "bla",
            "warn": true
        }
    },
    "msg": "non-zero return code",
    "rc": 1,
    "start": "2019-12-17 11:32:35.824545",
    "stderr": "/usr/share/kibana/src/legacy/server/utils/prompt.js:87\n            output.cursorTo(questionPrompt.length);\n                   ^\n\nTypeError: output.cursorTo is not a function\n    at Socket.input.on.char (/usr/share/kibana/src/legacy/server/utils/prompt.js:87:20)\n    at Socket.emit (events.js:194:15)\n    at addChunk (_stream_readable.js:284:12)\n    at readableAddChunk (_stream_readable.js:265:11)\n    at Socket.Readable.push (_stream_readable.js:220:10)\n    at Pipe.onStreamRead [as onread] (internal/stream_base_commons.js:94:17)",
    "stderr_lines": [
        "/usr/share/kibana/src/legacy/server/utils/prompt.js:87",
        "            output.cursorTo(questionPrompt.length);",
        "                   ^",
        "",
        "TypeError: output.cursorTo is not a function",
        "    at Socket.input.on.char (/usr/share/kibana/src/legacy/server/utils/prompt.js:87:20)",
        "    at Socket.emit (events.js:194:15)",
        "    at addChunk (_stream_readable.js:284:12)",
        "    at readableAddChunk (_stream_readable.js:265:11)",
        "    at Socket.Readable.push (_stream_readable.js:220:10)",
        "    at Pipe.onStreamRead [as onread] (internal/stream_base_commons.js:94:17)"
    ],
    "stdout": "Enter value for test26: ",
    "stdout_lines": [
        "Enter value for test26: "
    ]
}


I also tired using expect module as workaround (although I would like to avoid to install epel, pip, pexpect, etc. on the target machine just for running ansible):

- name: keystore - add elasticsearch.password
      expect:
        command: "./kibana-keystore add test28"
        chdir: "/usr/share/kibana/bin"
        responses:
          '.*value.*': "{{ CRED_KIBANA_PW }}"
        timeout: 10


Here I get this error in ansible:
fatal: [myserver]: FAILED! => {
    "changed": true,
    "cmd": "./kibana-keystore add test28",
    "delta": "0:00:10.528739",
    "end": "2019-12-17 11:32:49.123846",
    "invocation": {
        "module_args": {
            "chdir": "/usr/share/kibana/bin",
            "command": "./kibana-keystore add test28",
            "creates": null,
            "echo": false,
            "removes": null,
            "responses": {
                ".*value.*": "blubber"
            },
            "timeout": 10
        }
    },
    "msg": "command exceeded timeout",
    "rc": null,
    "start": "2019-12-17 11:32:38.595107",
    "stdout": "\u001b[1G\u001b[0JEnter value for test28: \u001b[25Gblubber\r\r\n\u001b[25G",
    "stdout_lines": [
        "\u001b[1G\u001b[0JEnter value for test28: \u001b[25Gblubber",
        "",
        "\u001b[25G"
    ]
}


Any idea where the error is?

Thanks, Andreas
Reply all
Reply to author
Forward
0 new messages