From 226d163e52c335bb8c5c7e1bb1b291c6d6307bfe Mon Sep 17 00:00:00 2001 From: pixelrebel Date: Mon, 5 Dec 2016 17:22:03 -0800 Subject: [PATCH 1/4] Only use es_api_host in API calls since es_config['network.host'] is not a reliable source --- handlers/elasticsearch-templates.yml | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/handlers/elasticsearch-templates.yml b/handlers/elasticsearch-templates.yml index b09cbc2..687d542 100644 --- a/handlers/elasticsearch-templates.yml +++ b/handlers/elasticsearch-templates.yml @@ -4,7 +4,7 @@ service: name={{instance_init_script | basename}} state=started enabled=yes - name: Wait for elasticsearch to startup - wait_for: host={% if es_config['network.host'] is defined %}{{es_config['network.host']}}{% else %}{{es_api_host}}{% endif %} port={% if es_config['http.port'] is defined %}{{es_config['http.port']}}{% else %}{{es_api_port}}{% endif %} delay=10 + wait_for: host="{{es_api_host}}" port={% if es_config['http.port'] is defined %}{{es_config['http.port']}}{% else %}{{es_api_port}}{% endif %} delay=10 - name: Get template files find: paths="/etc/elasticsearch/templates" patterns="*.json" @@ -12,7 +12,7 @@ - name: Install templates without auth uri: - url: "http://{% if es_config['network.host'] is defined %}{{es_config['network.host']}}{% else %}{{es_api_host}}{% endif %}:{% if es_config['http.port'] is defined %}{{es_config['http.port']}}{% else %}{{es_api_port}}{% endif %}/_template/{{item.path | filename}}" + url: "http://{{es_api_host}}:{% if es_config['http.port'] is defined %}{{es_config['http.port']}}{% else %}{{es_api_port}}{% endif %}/_template/{{item.path | filename}}" method: PUT status_code: 200 body_format: json @@ -22,7 +22,7 @@ - name: Install templates with auth uri: - url: "http://{% if es_config['network.host'] is defined %}{{es_config['network.host']}}{% else %}{{es_api_host}}{% endif %}:{% if es_config['http.port'] is defined %}{{es_config['http.port']}}{% else %}{{es_api_port}}{% endif %}/_template/{{item.path | filename}}" + url: "http://{{es_api_host}}:{% if es_config['http.port'] is defined %}{{es_config['http.port']}}{% else %}{{es_api_port}}{% endif %}/_template/{{item.path | filename}}" method: PUT status_code: 200 user: "{{es_api_basic_auth_username}}" From 68ad76bfe465806b43c0fc9367fedc9f87c2f2c7 Mon Sep 17 00:00:00 2001 From: pixelrebel Date: Tue, 6 Dec 2016 12:15:34 -0800 Subject: [PATCH 2/4] Parse/sanitize network.host and network.port, fallback to es_api_host/es_api_port --- handlers/elasticsearch-templates.yml | 39 +++++++++++++++++++++++++--- 1 file changed, 36 insertions(+), 3 deletions(-) diff --git a/handlers/elasticsearch-templates.yml b/handlers/elasticsearch-templates.yml index 687d542..f78dd38 100644 --- a/handlers/elasticsearch-templates.yml +++ b/handlers/elasticsearch-templates.yml @@ -3,8 +3,41 @@ - name: Ensure elasticsearch is started service: name={{instance_init_script | basename}} state=started enabled=yes +- set_fact: + es_config_host: "{{ item }}" + with_items: "{{ es_config['network.host'] }}" + when: + - es_config['network.host'] is defined and es_config['network.host'] is not string + - not item | match('^_.*_$') + - es_config_host is not defined + +- set_fact: + es_config_host: "{{ es_config['network.host'] }}" + when: + - es_config['network.host'] is defined and es_config['network.host'] is string + - not es_config['network.host'] | match('^_.*_$') + +- set_fact: + es_config_port: "{{ es_config['network.port'] }}" + when: + - es_config['network.port'] is defined and es_config['network.port'] is number + +- set_fact: + es_config_port: "{{ es_config['network.port'].split('-').0 }}" + when: + - es_config['network.port'] is defined and es_config['network.port'] is string + - es_config['network.port'] | match('^\d') + - name: Wait for elasticsearch to startup - wait_for: host="{{es_api_host}}" port={% if es_config['http.port'] is defined %}{{es_config['http.port']}}{% else %}{{es_api_port}}{% endif %} delay=10 + wait_for: + host: "{% if es_config_host is defined %}{{es_config_host}}{% else %}{{es_api_host}}{% endif %}" + port: "{% if es_config_port is defined %}{{es_config_port}}{% else %}{{es_api_port}}{% endif %}" + delay: 10 + +- name: Gather template files contents + shell: "cat /etc/elasticsearch/templates/{{ item }}" + with_items: "{{ es_template_files }}" + register: es_template_files_contents - name: Get template files find: paths="/etc/elasticsearch/templates" patterns="*.json" @@ -12,7 +45,7 @@ - name: Install templates without auth uri: - url: "http://{{es_api_host}}:{% if es_config['http.port'] is defined %}{{es_config['http.port']}}{% else %}{{es_api_port}}{% endif %}/_template/{{item.path | filename}}" + url: "http://{% if es_config_host is defined %}{{es_config_host}}{% else %}{{es_api_host}}{% endif %}:{% if es_config_port is defined %}{{es_config_port}}{% else %}{{es_api_port}}{% endif %}/_template/{{item.path | filename}}" method: PUT status_code: 200 body_format: json @@ -22,7 +55,7 @@ - name: Install templates with auth uri: - url: "http://{{es_api_host}}:{% if es_config['http.port'] is defined %}{{es_config['http.port']}}{% else %}{{es_api_port}}{% endif %}/_template/{{item.path | filename}}" + url: "http://{% if es_config_host is defined %}{{es_config_host}}{% else %}{{es_api_host}}{% endif %}:{% if es_config_port is defined %}{{es_config_port}}{% else %}{{es_api_port}}{% endif %}/_template/{{item.path | filename}}" method: PUT status_code: 200 user: "{{es_api_basic_auth_username}}" From 2dcd64c5f1a3e7dd56f2db26b2d7074465fe3b86 Mon Sep 17 00:00:00 2001 From: pixelrebel Date: Tue, 6 Dec 2016 12:20:06 -0800 Subject: [PATCH 3/4] Empty commit to resolve github push error From deaf5ea0fa0049726a5c935b26bf627b048340d0 Mon Sep 17 00:00:00 2001 From: pixelrebel Date: Tue, 6 Dec 2016 18:15:08 -0800 Subject: [PATCH 4/4] Fix mistake in URI body --- handlers/elasticsearch-templates.yml | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/handlers/elasticsearch-templates.yml b/handlers/elasticsearch-templates.yml index f78dd38..b2b175f 100644 --- a/handlers/elasticsearch-templates.yml +++ b/handlers/elasticsearch-templates.yml @@ -49,9 +49,9 @@ method: PUT status_code: 200 body_format: json - body: "{{ lookup('file', item.path) }}" + body: "{{ item.stdout }}" when: not es_enable_xpack or not es_xpack_features is defined or not '"shield" in es_xpack_features' - with_items: "{{ templates.files }}" + with_items: "{{ es_template_files_contents.results }}" - name: Install templates with auth uri: @@ -62,6 +62,6 @@ password: "{{es_api_basic_auth_password}}" force_basic_auth: yes body_format: json - body: "{{ lookup('file', item.path) }}" + body: "{{ item.stdout }}" when: es_enable_xpack and es_xpack_features is defined and '"shield" in es_xpack_features' - with_items: "{{ templates.files }}" + with_items: "{{ es_template_files_contents.results }}"