Fix handling of plugins when es_plugins_reinstall is false

* Get (and use) list of plugins that need to be installed
* Just remove all plugins of the remove list
This commit is contained in:
Maarten Bezemer 2017-03-20 14:28:11 +01:00
parent fce5eac4ce
commit f5e1a94869

View file

@ -28,12 +28,19 @@
- set_fact: plugins_to_remove="{{ installed_plugins.stdout_lines | difference(es_plugins | json_query('[*].plugin')) | default([]) }}" - set_fact: plugins_to_remove="{{ installed_plugins.stdout_lines | difference(es_plugins | json_query('[*].plugin')) | default([]) }}"
when: not es_plugins_reinstall when: not es_plugins_reinstall
#if es_plugins_reinstall is set to true we (re)install ALL plugins
- set_fact: plugins_to_install="{{ es_plugins | json_query('[*].plugin') | default([]) }}"
when: es_plugins_reinstall
#if the plugins listed are different than those requested, we install those not installed but listed in the config
- set_fact: plugins_to_install="{{ es_plugins | json_query('[*].plugin') | difference(installed_plugins.stdout_lines) | default([]) }}"
when: not es_plugins_reinstall
# This removes any currently installed plugins (to prevent errors when reinstalling) # This removes any currently installed plugins (to prevent errors when reinstalling)
- name: Remove elasticsearch plugins - name: Remove elasticsearch plugins
command: "{{es_home}}/bin/elasticsearch-plugin remove {{item}} --silent" command: "{{es_home}}/bin/elasticsearch-plugin remove {{item}} --silent"
ignore_errors: yes ignore_errors: yes
with_items: "{{ plugins_to_remove | default([]) }}" with_items: "{{ plugins_to_remove | default([]) }}"
when: es_plugins_reinstall and plugins_to_remove | length > 0
notify: restart elasticsearch notify: restart elasticsearch
register: plugin_removed register: plugin_removed
environment: environment:
@ -45,8 +52,8 @@
register: plugin_installed register: plugin_installed
failed_when: "'ERROR' in plugin_installed.stdout" failed_when: "'ERROR' in plugin_installed.stdout"
changed_when: plugin_installed.rc == 0 changed_when: plugin_installed.rc == 0
with_items: "{{ es_plugins | default([]) }}" with_items: "{{ es_plugins }}"
when: not es_plugins is none and es_plugins_reinstall when: "{{ item.plugin in plugins_to_install }}"
notify: restart elasticsearch notify: restart elasticsearch
environment: environment:
CONF_DIR: "{{ conf_dir }}" CONF_DIR: "{{ conf_dir }}"