elasticsearch - Elastic.elasticsearch 角色和 Ansible Tower 动态清单
问题描述
我正在尝试使用官方 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 自动缩放组构建的,并且我的主机是动态的......
干杯,德拉甘
解决方案
这是我解决这个问题的方法。它可能会帮助某人。
首先,我使用 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 Auto Scaling 和 Ansible elastic.elasticsearch 角色设置集群时,此配置非常有用。
推荐阅读
- android - 饼图或圆环图点击监听器
- javascript - 在谷歌应用程序脚本中声明通用可变二维数组
- api - 如何获取调用我的 API 的网站子域 URL?
- css - 具有在左侧延伸的顶部和底部边框的响应式英雄处理
- nativescript - nativescript:通过本地构建发布时出错
- c# - Xamarin 表单更改和启用图像按钮
- php - 我的 if 语句不起作用,每当我重新加载页面时,它总是以“用户已存在”开头
- java - 如何仅从 Font 和 FontRenderContext 获取 FontMetrics
- sql-server - 如何从 SQL 数据更改布局或表格
- database - 使用 Lambda 的 Redis 连接池