2015-05-13 13:33:43 +02:00
---
2015-12-13 22:46:50 +00:00
2016-05-25 19:24:58 +06:00
# es_plugins_reinstall will be set to true if elasticsearch_install_from_repo.changed or elasticsearch_install_from_package.changed
# i.e. we have changed ES version(or we have clean installation of ES), or if no plugins listed. Otherwise it is false and requires explicitly setting.
2018-02-04 07:09:23 +00:00
- name : set fact es_plugins_reinstall to true
set_fact : es_plugins_reinstall=true
2017-01-03 18:10:45 +00:00
when : (((debian_elasticsearch_install_from_repo is defined and debian_elasticsearch_install_from_repo.changed) or (redhat_elasticsearch_install_from_repo is defined and redhat_elasticsearch_install_from_repo.changed)) or (elasticsearch_install_from_package is defined and elasticsearch_install_from_package.changed)) or es_plugins is not defined or es_plugins is none
2016-07-24 17:48:42 +01:00
2018-02-04 07:09:23 +00:00
- name : set fact list_command
set_fact : list_command=""
2017-03-16 21:06:17 +00:00
#If we are reinstalling all plugins, e.g. to a version change, we need to remove all plugins (inc. x-pack) to install any plugins. Otherwise we don't consider x-pack so the role stays idempotent.
2018-02-04 07:09:23 +00:00
- name : set fact list_command check for x-pack
set_fact : list_command="| grep -vE 'x-pack'"
2017-03-16 21:06:17 +00:00
when : not es_plugins_reinstall
2016-07-22 23:44:27 +01:00
2018-08-28 07:58:50 +02:00
- name : remove x-pack plugin directory when it isn't a plugin
file :
dest : "{{ es_home }}/plugins/x-pack"
state : "absent"
2017-03-16 21:06:17 +00:00
#List currently installed plugins. We have to list the directories as the list commmand fails if the ES version is different than the plugin version.
2016-11-02 14:29:11 +01:00
- name : Check installed elasticsearch plugins
2017-05-12 13:31:50 -07:00
become : yes
2017-03-16 21:06:17 +00:00
shell : "ls {{es_home}}/plugins {{list_command}}"
2016-03-18 19:30:11 +00:00
register : installed_plugins
changed_when : False
2016-07-22 23:44:27 +01:00
ignore_errors : yes
2016-03-18 19:30:11 +00:00
environment :
2019-06-03 14:18:09 +02:00
CONF_DIR : "{{ es_conf_dir }}"
ES_PATH_CONF : "{{ es_conf_dir }}"
ES_INCLUDE : "{{ default_file }}"
2018-08-17 14:49:32 +02:00
check_mode : no
2016-01-19 11:50:02 +01:00
2017-03-16 21:06:17 +00:00
#if es_plugins_reinstall is set to true we remove ALL plugins
2018-02-04 07:09:23 +00:00
- name : set fact plugins_to_remove to install_plugins.stdout_lines
set_fact : plugins_to_remove="{{ installed_plugins.stdout_lines | default([]) }}"
2017-03-16 21:06:17 +00:00
when : es_plugins_reinstall
#if the plugins listed are different than those requested, we remove those installed but not listed in the config
2018-02-04 07:09:23 +00:00
- name : set fact plugins_to_remove to delete plugins installed but not listed in es_plugins
set_fact : plugins_to_remove="{{ installed_plugins.stdout_lines | difference(es_plugins | json_query('[*].plugin')) | default([]) }}"
2017-03-16 21:06:17 +00:00
when : not es_plugins_reinstall
2017-03-20 14:28:11 +01:00
#if es_plugins_reinstall is set to true we (re)install ALL plugins
2018-02-04 07:09:23 +00:00
- name : set fact plugins_to_install to es_plugins
set_fact : plugins_to_install="{{ es_plugins | json_query('[*].plugin') | default([]) }}"
2017-03-20 14:28:11 +01:00
when : es_plugins_reinstall
#if the plugins listed are different than those requested, we install those not installed but listed in the config
2018-02-04 07:09:23 +00:00
- name : set fact to plugins_to_install to those in es_config but not installed
set_fact : plugins_to_install="{{ es_plugins | json_query('[*].plugin') | difference(installed_plugins.stdout_lines) | default([]) }}"
2017-03-20 14:28:11 +01:00
when : not es_plugins_reinstall
2016-11-02 14:29:11 +01:00
# This removes any currently installed plugins (to prevent errors when reinstalling)
2015-05-13 13:33:43 +02:00
- name : Remove elasticsearch plugins
2017-05-12 13:31:50 -07:00
become : yes
2017-01-11 10:26:57 +00:00
command : "{{es_home}}/bin/elasticsearch-plugin remove {{item}} --silent"
2017-03-16 21:06:17 +00:00
with_items : "{{ plugins_to_remove | default([]) }}"
2015-12-13 22:46:50 +00:00
notify : restart elasticsearch
2016-11-02 14:29:11 +01:00
register : plugin_removed
2015-12-13 22:46:50 +00:00
environment :
2019-06-03 14:18:09 +02:00
CONF_DIR : "{{ es_conf_dir }}"
ES_PATH_CONF : "{{ es_conf_dir }}"
ES_INCLUDE : "{{ default_file }}"
2015-05-13 13:33:43 +02:00
- name : Install elasticsearch plugins
2017-05-12 13:31:50 -07:00
become : yes
2018-06-13 08:29:45 +02:00
command : "{{es_home}}/bin/elasticsearch-plugin install {{ item.url | default(item.plugin) }} --batch --silent"
2015-12-13 22:46:50 +00:00
register : plugin_installed
2021-04-12 14:25:04 +02:00
changed_when : plugin_installed.rc|default(0) == 0
2017-03-20 14:28:11 +01:00
with_items : "{{ es_plugins }}"
2017-08-15 14:31:56 +01:00
when : item.plugin in plugins_to_install
2015-12-13 22:46:50 +00:00
notify : restart elasticsearch
environment :
2019-06-03 14:18:09 +02:00
CONF_DIR : "{{ es_conf_dir }}"
ES_PATH_CONF : "{{ es_conf_dir }}"
ES_INCLUDE : "{{ default_file }}"
2021-04-12 14:25:04 +02:00
until : plugin_installed.rc|default(0) == 0
2016-11-25 17:21:13 +07:00
retries : 5
delay : 5