From b14224c0301d6f089f8815a28145776c22196522 Mon Sep 17 00:00:00 2001 From: Duncan Martin Walker Date: Wed, 19 Feb 2020 18:52:32 +0000 Subject: [PATCH] Expose Elasticsearch discovery nodes It is currently the case that the discovery information for elasticsearch nodes is generated using the elasticsearch node and kibana node groups internally. This means that one cannot connect to a remote cluster that is not managed by the same ansible inventory. This commit exposes the configuration to allow this to occur, permitting the elasticsearch discovery nodes to be optionally defined with further information. The associated internal variables have been renamed from zen_nodes as zen is used within Elasticsearch for discovery only internally, and the associated elasticsearch config file setting has been renamed to 'discovery.seed_hosts'. Change-Id: I76532c185e991eddcb1111fc58e7120a52c0120c --- elk_metrics_7x/roles/elastic_data_hosts/defaults/main.yml | 3 +++ .../roles/elastic_data_hosts/vars/data-node-variables.yml | 5 +++-- .../roles/elasticsearch/templates/elasticsearch.yml.j2 | 3 ++- elk_metrics_7x/showElasticCluster.yml | 4 ++-- 4 files changed, 10 insertions(+), 5 deletions(-) diff --git a/elk_metrics_7x/roles/elastic_data_hosts/defaults/main.yml b/elk_metrics_7x/roles/elastic_data_hosts/defaults/main.yml index 5c31b2b3..edc8bba0 100644 --- a/elk_metrics_7x/roles/elastic_data_hosts/defaults/main.yml +++ b/elk_metrics_7x/roles/elastic_data_hosts/defaults/main.yml @@ -34,3 +34,6 @@ elastic_data_interface: "{{ ansible_default_ipv4['alias'] }}" ## Elasticsearch index template settings # Set the default max number of fields used in a query # elastic_max_docvalue_fields_search: "100" + +# The set of nodes used for elasticsearch discovery +# elasticsearch_discovery_seed_hosts: "{{ (elastic_hosts | union(groups['kibana'])) | map('extract', hostvars, 'ansible_host') | list }}" diff --git a/elk_metrics_7x/roles/elastic_data_hosts/vars/data-node-variables.yml b/elk_metrics_7x/roles/elastic_data_hosts/vars/data-node-variables.yml index b72bcc5b..f167cb87 100644 --- a/elk_metrics_7x/roles/elastic_data_hosts/vars/data-node-variables.yml +++ b/elk_metrics_7x/roles/elastic_data_hosts/vars/data-node-variables.yml @@ -91,9 +91,10 @@ coordination_nodes: |- | map('regex_replace', '(.*)' ,'\1:' ~ elastic_port) | list)) }} -zen_nodes: >- +_elasticsearch_discovery_seed_hosts: >- {{ - (groups['elastic'] | union(groups['kibana'])) | map('extract', hostvars, 'ansible_host') | list | shuffle(seed=inventory_hostname) + elasticsearch_discovery_seed_hosts + | default((groups['elastic'] | union(groups['kibana'])) | map('extract', hostvars, 'ansible_host') | list) }} elasticserch_interface_speed: |- diff --git a/elk_metrics_7x/roles/elasticsearch/templates/elasticsearch.yml.j2 b/elk_metrics_7x/roles/elasticsearch/templates/elasticsearch.yml.j2 index d2eb058b..906cfcce 100644 --- a/elk_metrics_7x/roles/elasticsearch/templates/elasticsearch.yml.j2 +++ b/elk_metrics_7x/roles/elasticsearch/templates/elasticsearch.yml.j2 @@ -82,7 +82,8 @@ http.port: {{ elastic_port }} # Pass an initial list of hosts to perform discovery when this node is started: # The default list of hosts is ["127.0.0.1", "[::1]"] # -discovery.seed_hosts: {{ zen_nodes | to_json }} +discovery.seed_hosts: {{ _elasticsearch_discovery_seed_hosts | shuffle(seed=inventory_hostname) | to_json }} + # # Bootstrap the cluster using an initial set of master-eligible nodes: # diff --git a/elk_metrics_7x/showElasticCluster.yml b/elk_metrics_7x/showElasticCluster.yml index b818079f..082150ae 100644 --- a/elk_metrics_7x/showElasticCluster.yml +++ b/elk_metrics_7x/showElasticCluster.yml @@ -42,9 +42,9 @@ debug: msg: "Coordination nodes: {{ coordination_nodes }}" - - name: "Report Zen nodes" + - name: "Report Elasticsearch discovery nodes" debug: - msg: "Zen nodes: {{ zen_nodes }}" + msg: "Elasticsearch discovery nodes: {{ _elasticsearch_discovery_seed_hosts }}" delegate_to: elastic[0] run_once: true