diff --git a/tasks/elasticsearch-Debian.yml b/tasks/elasticsearch-Debian.yml index 15e697f..4311abb 100644 --- a/tasks/elasticsearch-Debian.yml +++ b/tasks/elasticsearch-Debian.yml @@ -10,7 +10,7 @@ - name: Debian - Ensure elasticsearch is installed apt: name=elasticsearch{% if es_version is defined and es_version != "" %}={{ es_version }}{% endif %} state=present cache_valid_time=86400 when: es_use_repository - register: elasticsearch_install + register: elasticsearch_install_from_repo - name: Debian - Download elasticsearch from url get_url: url={% if es_custom_package_url is defined %}{{ es_custom_package_url }}{% else %}{{ es_package_url }}-{{ es_version }}.deb{% endif %} dest=/tmp/elasticsearch-{{ es_version }}.deb validate_certs=no @@ -19,4 +19,4 @@ - name: Debian - Ensure elasticsearch is installed from downloaded package apt: deb=/tmp/elasticsearch-{{ es_version }}.deb when: not es_use_repository - register: elasticsearch_install \ No newline at end of file + register: elasticsearch_install_from_package diff --git a/tasks/elasticsearch-RedHat.yml b/tasks/elasticsearch-RedHat.yml index d01163d..0de8e71 100644 --- a/tasks/elasticsearch-RedHat.yml +++ b/tasks/elasticsearch-RedHat.yml @@ -14,9 +14,9 @@ - name: RedHat - Install Elasticsearch yum: name=elasticsearch{% if es_version is defined and es_version != "" %}-{{ es_version }}{% endif %} state=present update_cache=yes when: es_use_repository - register: elasticsearch_install + register: elasticsearch_install_from_repo - name: RedHat - Install Elasticsearch from url yum: name={% if es_custom_package_url is defined %}{{ es_custom_package_url }}{% else %}{{ es_package_url }}-{{ es_version }}.noarch.rpm{% endif %} state=present when: not es_use_repository - register: elasticsearch_install \ No newline at end of file + register: elasticsearch_install_from_package diff --git a/tasks/elasticsearch-plugins.yml b/tasks/elasticsearch-plugins.yml index dbba1c2..7da2d8c 100644 --- a/tasks/elasticsearch-plugins.yml +++ b/tasks/elasticsearch-plugins.yml @@ -1,8 +1,9 @@ --- -#es_plugins_reinstall will be set to true if elasticsearch_install.changed i.e. we have changed ES version, or if no plugins listed. Otherwise it is false and requires explicitly setting. +# 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. - set_fact: es_plugins_reinstall=true - when: (elasticsearch_install is defined and elasticsearch_install.changed) or es_plugins is not defined or es_plugins is none + when: ((elasticsearch_install_from_package is defined and 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 tags: - always @@ -41,7 +42,7 @@ failed_when: "'ERROR' in plugin_installed.stdout" changed_when: plugin_installed.rc == 0 with_items: "{{ es_plugins }}" - when: es_plugins is defined and not es_plugins is none + when: es_plugins is defined and not es_plugins is none and es_plugins_reinstall notify: restart elasticsearch environment: CONF_DIR: "{{ conf_dir }}" diff --git a/tasks/elasticsearch-plugins.yml.orig b/tasks/elasticsearch-plugins.yml.orig new file mode 100644 index 0000000..10888eb --- /dev/null +++ b/tasks/elasticsearch-plugins.yml.orig @@ -0,0 +1,57 @@ +--- + +# 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. +- set_fact: es_plugins_reinstall=true +<<<<<<< HEAD + when: (elasticsearch_install is defined and elasticsearch_install.changed) or es_plugins is not defined or es_plugins is none + tags: + - always +======= + when: (elasticsearch_install_from_repo.changed or elasticsearch_install_from_package.changed) or es_plugins is not defined or es_plugins is none +>>>>>>> ef1f19ab09d8645ce14c9a7e55d363614ac69237 + +- set_fact: list_command="list" + tags: + - always +- set_fact: list_command="--list" + when: es_version | version_compare('2.0', '<') + tags: + - always + +#List currently installed plugins +- shell: "{{es_home}}/bin/plugin {{list_command}} | sed -n '1!p' | cut -d '-' -f2-" + register: installed_plugins + changed_when: False + environment: + CONF_DIR: "{{ conf_dir }}" + ES_INCLUDE: "{{ instance_default_file }}" + +#This needs to removes any currently installed plugins +- name: Remove elasticsearch plugins + command: "{{es_home}}/bin/plugin remove {{item}} --silent" + ignore_errors: yes + with_items: "{{ installed_plugins.stdout_lines }}" + 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 + 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 + register: plugin_installed + failed_when: "'ERROR' in plugin_installed.stdout" + changed_when: plugin_installed.rc == 0 + with_items: "{{ es_plugins }}" + when: es_plugins is defined and not es_plugins is none and es_plugins_reinstall + notify: restart elasticsearch + environment: + CONF_DIR: "{{ conf_dir }}" + ES_INCLUDE: "{{ instance_default_file }}" + +#Set permissions on plugins directory +- name: Set Plugin Directory Permissions + file: state=directory path={{ plugin_dir }} owner={{ es_user }} group={{ es_group }} recurse=yes