这个ansible错误是什么意思?

What does this ansible error mean?

我刚刚开始学习 Ansible。我在安装 elasticsearch 的角色中定义了以下任务。

---
- name: install elasticsearch
  homebrew: name=elasticsearch state=present
- command: brew --prefix elasticsearch
  register: elasticsearch_home
- name: install elasticsearch-head
  command: "{{ elasticsearch_home.stdout }}/bin/plugin --install mobz/elasticsearch-head"
- name: install elasticsearch-analysis-icu
  command: "{{ elasticsearch_home.stdout }}/bin/plugin --install elasticsearch/elasticsearch-analysis-icu/2.2.0"
- name: install elasticsearch-inquisitor
  command: "{{ elasticsearch_home.stdout }}/bin/plugin --install polyfractal/elasticsearch-inquisitor"

我的剧本 运行 出现以下错误。

PLAY [all] ********************************************************************

GATHERING FACTS ***************************************************************
ok: [localhost]

TASK: [java | install latest java] ********************************************
ok: [localhost]

TASK: [elasticsearch | install elasticsearch] *********************************
ok: [localhost]

TASK: [elasticsearch | command brew --prefix elasticsearch] *******************
changed: [localhost]

TASK: [elasticsearch | install elasticsearch-head] ****************************
failed: [localhost] => {"changed": true, "cmd": "/usr/local/opt/elasticsearch/bin/plugin --install mobz/elasticsearch-head", "delta": "0:00:00.264923", "end": "2015-03-21 21:18:36.863296", "rc": 1, "start": "2015-03-21 21:18:36.598373", "warnings": []}
stderr: Exception in thread "main" org.elasticsearch.common.settings.SettingsException: Failed to load settings from [file:/Users/<username>/elasticsearch.yml]
at org.elasticsearch.common.settings.ImmutableSettings$Builder.loadFromStream(ImmutableSettings.java:947)
at org.elasticsearch.common.settings.ImmutableSettings$Builder.loadFromUrl(ImmutableSettings.java:931)
at org.elasticsearch.node.internal.InternalSettingsPreparer.prepareSettings(InternalSettingsPreparer.java:77)
at org.elasticsearch.plugins.PluginManager.main(PluginManager.java:389)
Caused by: org.elasticsearch.ElasticsearchParseException: malformed, expected settings to start with 'object', instead was [START_ARRAY]
at org.elasticsearch.common.settings.loader.XContentSettingsLoader.load(XContentSettingsLoader.java:65)
at org.elasticsearch.common.settings.loader.XContentSettingsLoader.load(XContentSettingsLoader.java:45)
at org.elasticsearch.common.settings.loader.YamlSettingsLoader.load(YamlSettingsLoader.java:46)
at org.elasticsearch.common.settings.ImmutableSettings$Builder.loadFromStream(ImmutableSettings.java:944)
... 3 more

FATAL: all hosts have already failed -- aborting

PLAY RECAP ********************************************************************
       to retry, use: --limit @/Users/<username>/elasticsearch.retry

localhost                  : ok=4    changed=1    unreachable=0    failed=1

起初我认为这可能是插件安装程序中的错误,它错误地处理了已安装插件的情况。我卸载了插件,然后 运行 再次播放,但我收到了完全相同的错误。我也尝试使用 shell 而不是 command,但结果没有区别。

stderr: Exception in thread "main" org.elasticsearch.common.settings.SettingsException: Failed to load settings from [file:/Users/<username>/elasticsearch.yml]

这一行让我觉得 elasticsearch 没有正确接收某些配置。但是我不明白为什么它会期望从 yml 文件中获取信息。即使有一些功能允许将设置管道设置到 elasticsearch 插件安装程序中,我希望使用 Ansible 的 shell 模块会在单独的 shell 中执行命令,因此 elasticsearch 将不知道yml 文件或 Ansible。有什么想法吗?

根据http://www.elastic.co/guide/en/elasticsearch/reference/master/setup-configuration.html

Elasticsearch Settings

elasticsearch configuration files can be found under ES_HOME/config folder. The folder comes with two files, the elasticsearch.yml for configuring Elasticsearch different modules, and logging.yml for configuring the Elasticsearch logging.

很可能发生的事情是 elasticsearch 感到困惑,并认为您的 playbook 文件是 elasticsearch 自己的配置文件。

解决此问题的最简单方法是将您的剧本文件重命名为不同的文件名。

然而,更合适的方法是修改您的任务以使用 command 模块的 chdir 参数。

- name: install elasticsearch-head
  command: "bin/plugin --install mobz/elasticsearch-head chdir={{ elasticsearch_home.stdout }}"

这样,这个命令是 运行 来自 ES 的 bin/ 目录。

更改 playbook 文件名的替代方法是使用 Ansible 的 chdir 功能进行 command 操作。

正在改变...

- name: install elasticsearch-head
  command: "{{ elasticsearch_home.stdout }}/bin/plugin --install mobz/elasticsearch-head"

...到...

- name: install elasticsearch-head
  command: "bin/plugin --install mobz/elasticsearch-head chdir={{ elasticsearch_home.stdout }}"

...解决问题。我更喜欢这个解决方案,因为它意味着我在选择文件名方面不受限制。但是,选择所选答案(和评论)是因为它描述了根本原因,并且只有在您关心文件名时才需要此解决方案。