我刚开始学习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 。有什么想法吗?
答案 0 :(得分:2)
根据http://www.elastic.co/guide/en/elasticsearch/reference/master/setup-configuration.html
Elasticsearch设置
可以在ES_HOME/config
文件夹下找到elasticsearch 配置文件。该文件夹附带两个文件,
elasticsearch.yml
用于配置Elasticsearch不同的模块,logging.yml
用于配置Elasticsearch日志记录。
所以最有可能发生的事情是弹性搜索感到困惑,并认为你的playbook文件是elasticsearch自己的配置文件。
解决此问题的最简单方法是将Playbook文件重命名为其他文件名。
但是,更正确的方法是修改任务以使用chdir
模块的command
参数。
- name: install elasticsearch-head
command: "bin/plugin --install mobz/elasticsearch-head chdir={{ elasticsearch_home.stdout }}"
这样,该命令从ES的 bin / 目录中运行。
答案 1 :(得分:2)
更改播放列表文件名的替代方法是使用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 }}"
......解决了这个问题。我更喜欢这个解决方案,因为这意味着我不会选择文件名。但是,选择的答案(和注释)是因为它描述了根本原因,只有在关心文件名时才需要此解决方案。