# How to fill keystore via ansible script

**URL:** <https://discuss.elastic.co/t/how-to-fill-keystore-via-ansible-script/212117>\
**Category:** Kibana\
**Created:** [December 17, 2019, 8:31am UTC](https://discuss.elastic.co/t/how-to-fill-keystore-via-ansible-script/212117 "2019-12-17T08:31:08Z")\
**Posts on this page:** 1\
**Showing post:** 4

<div class="post-metadata">

**Author:** ![asp](https://avatars.discourse-cdn.com/v4/letter/a/9fc348/32.png) [@asp](https://discuss.elastic.co/u/asp)\
**Post date:** [December 18, 2019, 9:08am UTC](https://discuss.elastic.co/t/how-to-fill-keystore-via-ansible-script/212117/4 "2019-12-18T09:08:02Z")

</div>

During creating the Bug Report I found this on github:

> <https://github.com/elastic/kibana/issues/52745>
>
> Currently we have the following output of $ bin/kibana-keystore add --help command:
> Usage: add \[options\] \<key\>
> Add a string setting to the keystore
> Options:
> ...

With the given information there I was able to get it running:

```
- name: keystore tasks
  block:
    - name: create keystore if not existing yet
      shell:
        cmd: "./kibana-keystore create"
        chdir: "/usr/share/kibana/bin"
        creates: /var/lib/kibana/kibana.keystore

    - name: keystore - add elasticsearch.password
      shell:
        cmd: "/usr/share/kibana/bin/kibana-keystore add elasticsearch.password --stdin --force"
        stdin: "{{ CRED_KIBANA_PW }}"
    - name: keystore - add elasticsearch.username
      shell:
        cmd: "/usr/share/kibana/bin/kibana-keystore add elasticsearch.username --stdin --force"
        stdin: "{{ CRED_KIBANA_USER }} "
  become_user: kibana
  become: yes

```

I had to take following 2 things into aspect:

- usage info of kibana-keystore is wrong -\> using like said in linked github request works from shell.
- piping the password via echo to kibana-keystore does not not work in ansible. But it works when calling kibana-keystore directly ans configuring stdin of shell module to the needed value.

---

_[View the full topic](https://discuss.elastic.co/t/how-to-fill-keystore-via-ansible-script/212117)._
