Ansible expect is not passing ansible variable on first pass. If I make changes and re run the script adding an additional response question then the script seems to work but if I just want to set this up initially first run scenario it doesn't work as expected.
First run scenario, it creates the setting in the keystore but never completes, the setting elasticsearch.username is created in the keystore but I cant verify if the name is actually added but the task fails with the error below, I have tried several different way to resolve this and nothing seems to work.
I am also making sure the keystore is empty and there are no values in the keystore before starting this process
- name: Create kibana elasticsearch user
expect:
command: sudo -E /usr/share/kibana/bin/kibana-keystore add elasticsearch.username
responses:
'username': "{{ elasticsearch_username }}
Error
fatal: [10.14.12.113]: FAILED! => {"changed": true, "cmd": "sudo -E /usr/share/kibana/bin/kibana-keystore add elasticsearch.username", "delta": "0:00:30.610819", "end": "2019-03-19 20:32:45.320395", "msg": "command exceeded timeout", "rc": null, "start": "2019-03-19 20:32:14.709576", "stdout": "\u001b[1G\u001b[0JEnter value for elasticsearch.username: \u001b[41Gkibana\r\r\n\u001b[41G", "stdout_lines": ["\u001b[1G\u001b[0JEnter value for elasticsearch.username: \u001b[41Gkibana", "", "\u001b[41G"]}
If I run this a second time adding in the response question to overwrite the value in the keystore after it was added then this seems to work with out any issue and therefore doesn't seem to make sense why it fails the first round just adding in the value the first time.
Manual cli runs run with no issues.
- name: Create kibana elasticsearch user
expect:
command: sudo -E /usr/share/kibana/bin/kibana-keystore add elasticsearch.username
responses:
'Overwrite\? \[y/N\]': "y"
'username': "{{ elasticsearch_username }}"
No error
TASK [Create kibana elasticsearch user] *********************************
changed: [xxx.xxx.xxx.xxx]
With more testing i see the username being populated but appears that it may not be sending a return to continue.
ansible -vvvv
fatal: [10.14.12.113]: FAILED! => {
"changed": true,
"cmd": "/usr/share/kibana/bin/kibana-keystore add elasticsearch.username",
"delta": "0:00:30.613915",
"end": "2019-03-21 19:26:01.959953",
"invocation": {
"module_args": {
"chdir": null,
"command": "/usr/share/kibana/bin/kibana-keystore add elasticsearch.username",
"creates": null,
"echo": false,
"removes": null,
"responses": {
"Enter value for elasticsearch.username": "kibana"
},
"timeout": 30
}
},
"msg": "command exceeded timeout",
"rc": null,
"start": "2019-03-21 19:25:31.346038",
"stdout": "\u001b[1G\u001b[0JEnter value for elasticsearch.username: \u001b[41Gkibana\r\r\n\u001b[41G",
"stdout_lines": [
"\u001b[1G\u001b[0JEnter value for elasticsearch.username: \u001b[41Gkibana",
"",
"\u001b[41G"
]
}
Thanks in advance for you help