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

**URL:** <https://forum.ansible.com/t/how-to-add-key-to-elastics-kibana-keystore-via-ansible-script/31833>\
**Category:** Ansible Project\
**Created:** [December 17, 2019, 10:38am UTC](https://forum.ansible.com/t/how-to-add-key-to-elastics-kibana-keystore-via-ansible-script/31833 "2019-12-17T10:38:19Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![Andreas\_Schampera](https://avatars.discourse-cdn.com/v4/letter/a/e79b87/32.png) [@Andreas\_Schampera](https://forum.ansible.com/u/Andreas_Schampera)\
**Post date:** [December 17, 2019, 10:38am UTC](https://forum.ansible.com/t/how-to-add-key-to-elastics-kibana-keystore-via-ansible-script/31833/1 "2019-12-17T10:38:19Z")

</div>

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
