我才刚开始学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。有什么想法吗?
发布于 2015-03-23 05:29:25
根据http://www.elastic.co/guide/en/elasticsearch/reference/master/setup-configuration.html
弹性搜索设置 elasticsearch配置文件可以在
ES_HOME/config文件夹下找到。该文件夹附带两个文件:配置Elasticsearch不同模块的elasticsearch.yml和配置Elasticsearch日志记录的logging.yml。
因此,最有可能发生的事情是elasticsearch混淆了,认为您的剧本文件是elasticsearch自己的配置文件。
解决此问题的最简单方法是将您的剧本文件重命名为不同的文件名。
但是,更正确的方法是修改任务以使用chdir模块的command参数。
- name: install elasticsearch-head
command: "bin/plugin --install mobz/elasticsearch-head chdir={{ elasticsearch_home.stdout }}"这样,这个命令就从ES的bin/目录中运行。
发布于 2015-03-23 14:28:59
更改剧本文件名的另一种方法是将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 }}"..。解决了问题。我更喜欢这个解决方案,因为它意味着我不受文件名选择的限制。但是,选择所选的答案(和注释)是因为它描述了根本原因,而且只有当您关心文件名时,此解决方案才是必要的。
https://stackoverflow.com/questions/29190666
复制相似问题