From 2771eb2a92e8a7f421d57280aef0a01ec87abae5 Mon Sep 17 00:00:00 2001 From: Maarten Bezemer Date: Wed, 2 Nov 2016 14:29:11 +0100 Subject: [PATCH 1/4] Add binary prefix for version 5.x --- tasks/elasticsearch-plugins.yml | 17 +++++++++++------ tasks/xpack/elasticsearch-xpack-install.yml | 8 ++++---- tasks/xpack/elasticsearch-xpack.yml | 8 ++++---- 3 files changed, 19 insertions(+), 14 deletions(-) diff --git a/tasks/elasticsearch-plugins.yml b/tasks/elasticsearch-plugins.yml index 14f6a33..67d5517 100644 --- a/tasks/elasticsearch-plugins.yml +++ b/tasks/elasticsearch-plugins.yml @@ -10,8 +10,14 @@ - set_fact: list_command="--list" when: es_version | version_compare('2.0', '<') +- set_fact: es_binary_prefix="" + +- set_fact: es_binary_prefix="elasticsearch-" + when: es_version | version_compare('2.0', '>') + #List currently installed plugins - ignore xpack if > v 2.0 -- shell: "{{es_home}}/bin/plugin {{list_command}} | sed -n '1!p' | cut -d '-' -f2-{% if es_version | version_compare('2.0', '>') %} | grep -vE '{{supported_xpack_features | join('|')}}|license'{% endif %}" +- name: Check installed elasticsearch plugins + shell: "{{es_home}}/bin/{{ es_binary_prefix }}plugin {{list_command}}{% if es_version | version_compare('2.0', '>') %} | grep -vE '{{supported_xpack_features | join('|')}}|license'{% endif %}" register: installed_plugins failed_when: "'ERROR' in installed_plugins.stdout" changed_when: False @@ -20,22 +26,21 @@ CONF_DIR: "{{ conf_dir }}" ES_INCLUDE: "{{ instance_default_file }}" -#This needs to removes any currently installed plugins +# This removes any currently installed plugins (to prevent errors when reinstalling) - name: Remove elasticsearch plugins - command: "{{es_home}}/bin/plugin remove {{item}} --silent" + command: "{{es_home}}/bin/{{ es_binary_prefix }}plugin remove {{item}} --silent" ignore_errors: yes with_items: "{{ installed_plugins.stdout_lines | default([]) }}" when: es_plugins_reinstall and installed_plugins.stdout_lines | length > 0 and not 'No plugin detected' in installed_plugins.stdout_lines[0] notify: restart elasticsearch - register: plugin_installed + register: plugin_removed environment: CONF_DIR: "{{ conf_dir }}" ES_INCLUDE: "{{ instance_default_file }}" - name: Install elasticsearch plugins - #debug: var=item command: > - {{es_home}}/bin/plugin install {{ item.plugin }}{% if item.version is defined and item.version != '' %}/{{ item.version }}{% endif %} {% if item.proxy_host is defined and item.proxy_host != '' and item.proxy_port is defined and item.proxy_port != ''%} -DproxyHost={{ item.proxy_host }} -DproxyPort={{ item.proxy_port }} {% elif es_proxy_host is defined and es_proxy_host != '' %} -DproxyHost={{ es_proxy_host }} -DproxyPort={{ es_proxy_port }} {% endif %} --silent + {{es_home}}/bin/{{ es_binary_prefix }}plugin install {{ item.plugin }}{% if item.version is defined and item.version != '' %}/{{ item.version }}{% endif %} {% if item.proxy_host is defined and item.proxy_host != '' and item.proxy_port is defined and item.proxy_port != ''%} -DproxyHost={{ item.proxy_host }} -DproxyPort={{ item.proxy_port }} {% elif es_proxy_host is defined and es_proxy_host != '' %} -DproxyHost={{ es_proxy_host }} -DproxyPort={{ es_proxy_port }} {% endif %} --silent register: plugin_installed failed_when: "'ERROR' in plugin_installed.stdout" changed_when: plugin_installed.rc == 0 diff --git a/tasks/xpack/elasticsearch-xpack-install.yml b/tasks/xpack/elasticsearch-xpack-install.yml index 77ddc58..9fe3a2d 100644 --- a/tasks/xpack/elasticsearch-xpack-install.yml +++ b/tasks/xpack/elasticsearch-xpack-install.yml @@ -1,7 +1,7 @@ --- #Test if feature is installed -- shell: "{{es_home}}/bin/plugin list | sed -n '1!p' | grep {{item}}" +- shell: "{{es_home}}/bin/{{ es_binary_prefix }}plugin list | sed -n '1!p' | grep {{item}}" register: feature_installed changed_when: False failed_when: "'ERROR' in feature_installed.stdout" @@ -14,7 +14,7 @@ #Remove Plugin if installed and its not been requested or the ES version has changed - name: Remove {{item}} plugin command: > - {{es_home}}/bin/plugin remove shield + {{es_home}}/bin/{{ es_binary_prefix }}plugin remove shield register: xpack_state failed_when: "'ERROR' in xpack_state.stdout" changed_when: xpack_state.rc == 0 @@ -28,7 +28,7 @@ #Install plugin if not installed, or the es version has changed (so removed above), and its been requested - name: Install {{item}} plugin command: > - {{es_home}}/bin/plugin install {{item}} + {{es_home}}/bin/{{ es_binary_prefix }}plugin install {{item}} register: xpack_state failed_when: "'ERROR' in xpack_state.stdout" changed_when: xpack_state.rc == 0 @@ -36,4 +36,4 @@ notify: restart elasticsearch environment: CONF_DIR: "{{ conf_dir }}" - ES_INCLUDE: "{{ instance_default_file }}" \ No newline at end of file + ES_INCLUDE: "{{ instance_default_file }}" diff --git a/tasks/xpack/elasticsearch-xpack.yml b/tasks/xpack/elasticsearch-xpack.yml index 46be973..87282fc 100644 --- a/tasks/xpack/elasticsearch-xpack.yml +++ b/tasks/xpack/elasticsearch-xpack.yml @@ -7,7 +7,7 @@ #Check if license is installed - name: Check License is installed shell: > - {{es_home}}/bin/plugin list | tail -n +2 | grep license + {{es_home}}/bin/{{ es_binary_prefix }}plugin list | tail -n +2 | grep license register: license_installed ignore_errors: yes failed_when: "'ERROR' in license_installed.stdout" @@ -19,7 +19,7 @@ #Remove license if installed and xpack not enabled - name: Remove license plugin command: > - {{es_home}}/bin/plugin remove license + {{es_home}}/bin/{{ es_binary_prefix }}plugin remove license register: xpack_state failed_when: "'ERROR' in xpack_state.stdout" changed_when: xpack_state.rc == 0 @@ -32,7 +32,7 @@ #Install License if not installed, or it needs to be reinstalled due to ES change (above task will have removed), and its been requested. - name: Install license plugin command: > - {{es_home}}/bin/plugin install license + {{es_home}}/bin/{{ es_binary_prefix }}plugin install license register: xpack_state failed_when: "'ERROR' in xpack_state.stdout" changed_when: xpack_state.rc == 0 @@ -52,4 +52,4 @@ #Add any feature specific configuration here - name: Set Plugin Directory Permissions - file: state=directory path={{ es_home }}/plugins owner={{ es_user }} group={{ es_group }} recurse=yes \ No newline at end of file + file: state=directory path={{ es_home }}/plugins owner={{ es_user }} group={{ es_group }} recurse=yes From bfb74b96a449d5dbf060bea01afd2772701709c9 Mon Sep 17 00:00:00 2001 From: Maarten Bezemer Date: Fri, 4 Nov 2016 15:55:46 +0100 Subject: [PATCH 2/4] Fix version check for plugin prefix --- tasks/elasticsearch-plugins.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tasks/elasticsearch-plugins.yml b/tasks/elasticsearch-plugins.yml index 67d5517..6e80637 100644 --- a/tasks/elasticsearch-plugins.yml +++ b/tasks/elasticsearch-plugins.yml @@ -13,7 +13,7 @@ - set_fact: es_binary_prefix="" - set_fact: es_binary_prefix="elasticsearch-" - when: es_version | version_compare('2.0', '>') + when: es_version | version_compare('5.0', '>=') #List currently installed plugins - ignore xpack if > v 2.0 - name: Check installed elasticsearch plugins From d341a4c0eaec9c39d366bc6c2e6ef64551671396 Mon Sep 17 00:00:00 2001 From: Maarten Bezemer Date: Fri, 4 Nov 2016 15:56:27 +0100 Subject: [PATCH 3/4] Version 2.X does need the filter to parse the plugin output --- tasks/elasticsearch-plugins.yml | 2 +- tasks/xpack/elasticsearch-xpack-install.yml | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/tasks/elasticsearch-plugins.yml b/tasks/elasticsearch-plugins.yml index 6e80637..b99cfcc 100644 --- a/tasks/elasticsearch-plugins.yml +++ b/tasks/elasticsearch-plugins.yml @@ -17,7 +17,7 @@ #List currently installed plugins - ignore xpack if > v 2.0 - name: Check installed elasticsearch plugins - shell: "{{es_home}}/bin/{{ es_binary_prefix }}plugin {{list_command}}{% if es_version | version_compare('2.0', '>') %} | grep -vE '{{supported_xpack_features | join('|')}}|license'{% endif %}" + shell: "{{es_home}}/bin/{{ es_binary_prefix }}plugin {{list_command}}{% if es_version | version_compare('5.0', '<') %} | sed -n '1!p' | cut -d '-' -f2-{% endif %}{% if es_version | version_compare('2.0', '>') %} | grep -vE '{{supported_xpack_features | join('|')}}|license'{% endif %}" register: installed_plugins failed_when: "'ERROR' in installed_plugins.stdout" changed_when: False diff --git a/tasks/xpack/elasticsearch-xpack-install.yml b/tasks/xpack/elasticsearch-xpack-install.yml index 9fe3a2d..ff64c0b 100644 --- a/tasks/xpack/elasticsearch-xpack-install.yml +++ b/tasks/xpack/elasticsearch-xpack-install.yml @@ -1,7 +1,7 @@ --- #Test if feature is installed -- shell: "{{es_home}}/bin/{{ es_binary_prefix }}plugin list | sed -n '1!p' | grep {{item}}" +- shell: "{{es_home}}/bin/{{ es_binary_prefix }}plugin list{% if es_version | version_compare('5.0', '<') %} | sed -n '1!p' | cut -d '-' -f2-{% endif %} | grep {{item}}" register: feature_installed changed_when: False failed_when: "'ERROR' in feature_installed.stdout" From 49dfa81684a351b2259fcfa747366136217842b9 Mon Sep 17 00:00:00 2001 From: Maarten Bezemer Date: Wed, 7 Dec 2016 22:54:33 +0100 Subject: [PATCH 4/4] Make prefix available when es_plugins is not defined --- tasks/elasticsearch-plugins.yml | 5 ----- tasks/elasticsearch.yml | 5 +++++ 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/tasks/elasticsearch-plugins.yml b/tasks/elasticsearch-plugins.yml index b99cfcc..ae53943 100644 --- a/tasks/elasticsearch-plugins.yml +++ b/tasks/elasticsearch-plugins.yml @@ -10,11 +10,6 @@ - set_fact: list_command="--list" when: es_version | version_compare('2.0', '<') -- set_fact: es_binary_prefix="" - -- set_fact: es_binary_prefix="elasticsearch-" - when: es_version | version_compare('5.0', '>=') - #List currently installed plugins - ignore xpack if > v 2.0 - name: Check installed elasticsearch plugins shell: "{{es_home}}/bin/{{ es_binary_prefix }}plugin {{list_command}}{% if es_version | version_compare('5.0', '<') %} | sed -n '1!p' | cut -d '-' -f2-{% endif %}{% if es_version | version_compare('2.0', '>') %} | grep -vE '{{supported_xpack_features | join('|')}}|license'{% endif %}" diff --git a/tasks/elasticsearch.yml b/tasks/elasticsearch.yml index 7addb03..71ad9e1 100644 --- a/tasks/elasticsearch.yml +++ b/tasks/elasticsearch.yml @@ -1,5 +1,10 @@ --- +- set_fact: es_binary_prefix="" + +- set_fact: es_binary_prefix="elasticsearch-" + when: es_version | version_compare('5.0', '>=') + - name: Include optional user and group creation. when: (es_user_id is defined) and (es_group_id is defined) include: elasticsearch-optional-user.yml