0

我写了一个 ansible 角色来安装 elasticsearch 多节点集群,问题是我为每种类型的节点(主节点、数据节点)都有一个配置文件。我在每个剧本中指定主机时遇到问题。

setup_elastic.yml

---
- hosts: all
  become: yes
  become_user: root
  roles:
  - elasticsearch

这是大师的配置文件:

---
    - name: config elasticsearch master
      blockinfile:
          path: /etc/elasticsearch/elasticsearch.yml
          block: |
                    cluster.name: lamedicale4
                    node.master: true
                    node.data: false
                    node.name: ${HOSTNAME}
                    bootstrap.mlockall: true
                    path.data: /data/elasticsearch
                    path.logs: /logs/elasticsearch
                    discovery.zen.minimum_master_nodes: 2
                    discovery.zen.ping.multicast.enabled: false
                    discovery.zen.ping.unicast.hosts : ["172.31.36.229","172.31.44.124"]

数据节点的配置文件:

---
    - name: config elasticsearch data nodes
      blockinfile:
          path: /etc/elasticsearch/elasticsearch.yml
          block: |
                    cluster.name: lamedicale4
                    node.master: false
                    node.data: true
                    node.name: ${HOSTNAME}
                    bootstrap.mlockall: true
                    path.data: /data/elasticsearch
                    path.logs: /logs/elasticsearch
                    discovery.zen.minimum_master_nodes: 2
                    discovery.zen.ping.multicast.enabled: false
                    discovery.zen.ping.unicast.hosts : ["172.31.36.229","172.31.44.124"]

这是主要任务:

---
# tasks file for /etc/ansible/roles/elastissearch

- import_tasks: install_java_jdk.yml
- import_tasks: install_elasticsearch.yml
- import_tasks: clear_file.yml
- import_tasks: directory_data_log_elastic.yml
- include_tasks: config_elasticsearch_master.yml
- include_tasks: config_elasticsearch_data.yml
- import_tasks: reload_restart_elasticsearch.yml

我应该怎么办 ?

4

1 回答 1

0

回答您的具体问题,替换${HOSTNAME}为:

  • {{库存主机名}}
  • {{ ansible_fqdn }}
  • {{ ansible_hostname }}

查看文档的这一部分以了解这些内容的来源。

更一般地说,我建议使用更灵活的“blockinfile”方法,将整个配置文件转换为 Ansible 模板,并使用“模板”模块进行管理。我过去曾使用 Elasticsearch 配置文件完成此操作,并且效果很好。

于 2018-12-21T11:44:23.537 回答