How to fill keystore via ansible script

During creating the Bug Report I found this on github:

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.