0

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

kcomer
  • 21
  • 1
  • 3
  • I believe that this command went timeout because of sudo's prompt timeout. Is responses mapping corrected ? Could you please show the output of the command when running by hands: `sudo -E /usr/share/kibana/bin/kibana-keystore add elasticsearch.username` – jasonz Mar 20 '19 at 07:53
  • as non root user I get this from command line sudo -E /usr/share/kibana/bin/kibana-keystore add elasticsearch.username Enter value for elasticsearch.username: ****** – kcomer Mar 20 '19 at 15:53
  • as root user I get this # sudo -E /usr/share/kibana/bin/kibana-keystore remove elasticsearch.username ~]# – kcomer Mar 20 '19 at 15:54
  • Is responses mapping corrected ? Yes response mapping is correct or works as it is when I use the First response with the second response, when the second response is used alone on a fresh or clean keystore it fails – kcomer Mar 20 '19 at 15:57
  • If I disable sudo in my playbook and leave sudo -e in the command I get an issue with it requiring pexpect so I assume the command is not able to sudo TASK [Install pexpect] ***************************************************************************************************************************************** fatal: []: FAILED! => {"changed": false, "cmd": ["/usr/bin/pip2", "install", "pexpect"], "msg": "\n:stderr: Traceback (most recent call last):\n File \"/usr/bin/pip2\", line 7, in \n from pip._internal import main\nImportError: No module named pip._internal\n"} – kcomer Mar 20 '19 at 17:03

0 Answers0