Elastic.elasticsearch角色和Ansible塔式动态库存

问题描述 投票:-1回答:1

我正在尝试使用官方Elastic Ansible角色elastic.elasticsearch在Ansible上配置Elasticsearch集群。我为我的AWS实例设置了Ansible塔式服务器和动态库存。我标记了实例,并将它们全部分组在tag_Group_Elasticsearch中。这是Ansible代码:

  hosts: tag_Group_Elasticsearch
  roles:
    - role: elastic.elasticsearch
  vars:
    es_heap_size: "2g"
    es_config:
      network.host: 0.0.0.0
      cluster.name: "prod-cluster"
      cluster.initial_master_nodes: "tag_Group_Elasticsearch"
      discovery.seed_hosts: "tag_Group_Elasticsearch"
      http.port: 9200
      node.master: true
      bootstrap.memory_lock: false
    es_plugins:
     - plugin: ingest-attachment

因此,当我想以角色的形式使用该小组时,在主持演出的一部分时效果很好。它可以很好地解析并适用于组中的所有主机。但是,当我想在es_config变量中使用它时,它不能解析为主机名,而只是将其作为字符串传递,因此,Elasticsearch集群失败。

这是我在集群成员上的elasticsearch.yml中得到的:

cluster.initial_master_nodes: tag_Group_Elasticsearch
discovery.seed_hosts: tag_Group_Elasticsearch

我需要在这里提供:

cluster.initial_master_nodes: "192.168.x.x, 192.168.x.x, 192.168.x.x "
discovery.seed_hosts: "192.168.x.x, 192.168.x.x, 192.168.x.x"

我无法在cluster.initial_master_nodes和discovery.seed_hosts中手动添加主机名,因为我的Elasticsearch集群是通过AWS自动扩展组构建的,并且我的主机是动态的...

干杯,德拉甘

elasticsearch ansible autoscaling ansible-inventory ansible-tower
1个回答
0
投票

这是我解决此问题的方法。它可能会帮助某人。

首先,我使用set_fact创建了新变量:

- name: Determine nodes to join
  hosts: tag_Group_Elasticsearch
  become: true
  tasks:
  - name: Setting nodes IPs
    set_fact:
      join_list: "{{ groups['tag_Group_Elasticsearch'] | map('extract', hostvars, ['ansible_host']) | list }}" # instead 'ansible_host' you can use the folloving variables as well: ansible_fqdn, ec2_private_ip_address or ansible_nodename

然后,我以elastic.elasticsearch角色将cluster.initial_master_nodes和discovery.seed_hosts配置如下:

cluster.initial_master_nodes: "{{ join_list | join(',') }}"
discovery.seed_hosts: "{{ join_list | join(',') }}"

因此,elasticsearch.yaml获得了节点的IP地址:

cluster.initial_master_nodes: 10.174.x.x,10.174.x.x,10.174.x.x
discovery.seed_hosts: 10.174.x.x,10.174.x.x,10.174.x.x

现在,每当将新节点添加到组中(在本例中为tag_Group_Elasticsearch时,该节点将被自动添加到cluster.initial_master_nodes和Discovery.seed_hosts中。

当您在AWS(EC2)中具有集群节点,并且使用AWS自动缩放和Ansible elastic.elasticsearch角色来设置集群时,此配置非常有用。

© www.soinside.com 2019 - 2024. All rights reserved.