From 3e265a467d1f981ae85d126bfcf4cd694f00abfc Mon Sep 17 00:00:00 2001 From: Michael Russell Date: Thu, 27 Dec 2018 16:42:14 +0100 Subject: [PATCH 01/11] Allow switching between oss and standard packages Before only going from the standard package to oss was supported. Now this works properly in both directions. --- tasks/compatibility-variables.yml | 2 ++ tasks/elasticsearch-Debian.yml | 11 +++++------ tasks/elasticsearch-RedHat.yml | 5 ++--- 3 files changed, 9 insertions(+), 9 deletions(-) diff --git a/tasks/compatibility-variables.yml b/tasks/compatibility-variables.yml index e56e3c1..639534d 100644 --- a/tasks/compatibility-variables.yml +++ b/tasks/compatibility-variables.yml @@ -14,6 +14,7 @@ es_xpack_conf_subdir: "" es_repo_name: "{{ es_major_version }}" es_xpack_users_command: "elasticsearch-users" + es_other_package_name: "elasticsearch-oss" - name: Detect if es_version is before X-Pack was open and included set_fact: @@ -33,6 +34,7 @@ set_fact: es_repo_name: "{{ 'oss-' + es_major_version }}" es_package_name: "elasticsearch-oss" + es_other_package_name: "elasticsearch" when: - es_open_xpack - not es_enable_xpack diff --git a/tasks/elasticsearch-Debian.yml b/tasks/elasticsearch-Debian.yml index eec8be8..680f654 100644 --- a/tasks/elasticsearch-Debian.yml +++ b/tasks/elasticsearch-Debian.yml @@ -26,12 +26,10 @@ when: es_use_repository -- name: Gracefully stop and remove elasticsearch if we are switching to the oss version - when: - - es_package_name == 'elasticsearch-oss' +- name: Gracefully stop and remove elasticsearch package if switching between OSS and standard block: - name: Check if the elasticsearch package is installed - shell: dpkg-query -W -f'${Status}' elasticsearch + shell: "dpkg-query -W -f'${Status}' {{ es_other_package_name }}" register: elasticsearch_package failed_when: False changed_when: False @@ -43,13 +41,14 @@ state: stopped when: elasticsearch_package.stdout == 'install ok installed' - - name: Debian - Remove elasticsearch package if we are installing the oss package + - name: Debian - Remove elasticsearch package if we are switching to a different package type become: yes apt: - name: 'elasticsearch' + name: '{{ es_other_package_name }}' state: absent when: elasticsearch_package.stdout == 'install ok installed' + - name: Debian - Ensure elasticsearch is installed become: yes apt: diff --git a/tasks/elasticsearch-RedHat.yml b/tasks/elasticsearch-RedHat.yml index a57ab71..aa59b9c 100644 --- a/tasks/elasticsearch-RedHat.yml +++ b/tasks/elasticsearch-RedHat.yml @@ -20,12 +20,11 @@ include: elasticsearch-RedHat-version-lock.yml when: es_version_lock -- name: RedHat - Remove non oss package if the old elasticsearch package is installed +- name: RedHat - Remove the other elasticsearch package if switching between OSS and standard become: yes yum: - name: 'elasticsearch' + name: es_other_package_name state: 'absent' - when: es_package_name == 'elasticsearch-oss' - name: RedHat - Install Elasticsearch become: yes From c2e51f8ecfdcb99c8e2b0b177b372ac7fcd432ee Mon Sep 17 00:00:00 2001 From: Michael Russell Date: Thu, 27 Dec 2018 17:35:44 +0100 Subject: [PATCH 02/11] Fix jinja syntax variable fun How it was previously "worked" but just ignored trying to remove the package. Luckily it was caught by the test-kitchen testing! --- tasks/elasticsearch-RedHat.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tasks/elasticsearch-RedHat.yml b/tasks/elasticsearch-RedHat.yml index aa59b9c..d002991 100644 --- a/tasks/elasticsearch-RedHat.yml +++ b/tasks/elasticsearch-RedHat.yml @@ -23,7 +23,7 @@ - name: RedHat - Remove the other elasticsearch package if switching between OSS and standard become: yes yum: - name: es_other_package_name + name: '{{ es_other_package_name }}' state: 'absent' - name: RedHat - Install Elasticsearch From 69c49fc0cd28569458a09182a356ab4c4dfb8615 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Karri=20Niemel=C3=A4?= Date: Mon, 19 Nov 2018 09:32:30 +0200 Subject: [PATCH 03/11] Update elasticsearch-parameters.yml Fixing data_dirs name typo --- tasks/elasticsearch-parameters.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tasks/elasticsearch-parameters.yml b/tasks/elasticsearch-parameters.yml index dc8a177..df1ba0e 100644 --- a/tasks/elasticsearch-parameters.yml +++ b/tasks/elasticsearch-parameters.yml @@ -71,5 +71,5 @@ set_fact: pid_dir={{ es_pid_dir }}/{{instance_suffix}} - name: set fact log_dir set_fact: log_dir={{ es_log_dir }}/{{instance_suffix}} -- name: set fact log_dir +- name: set fact data_dirs set_fact: data_dirs={{ es_data_dirs | append_to_list('/'+instance_suffix) }} From 486717bc6f4936c244a6c9497f2f8686cab289dd Mon Sep 17 00:00:00 2001 From: Michael Russell Date: Mon, 31 Dec 2018 17:28:37 +0100 Subject: [PATCH 04/11] Remove the other Elasticsearch repo when switching versions --- tasks/compatibility-variables.yml | 2 ++ tasks/elasticsearch-RedHat.yml | 11 ++++++++++- 2 files changed, 12 insertions(+), 1 deletion(-) diff --git a/tasks/compatibility-variables.yml b/tasks/compatibility-variables.yml index 639534d..2116dfd 100644 --- a/tasks/compatibility-variables.yml +++ b/tasks/compatibility-variables.yml @@ -15,6 +15,7 @@ es_repo_name: "{{ es_major_version }}" es_xpack_users_command: "elasticsearch-users" es_other_package_name: "elasticsearch-oss" + es_other_repo_name: "{{ 'oss-' + es_major_version }}" - name: Detect if es_version is before X-Pack was open and included set_fact: @@ -33,6 +34,7 @@ - name: Use the oss repo and package if xpack is not being used set_fact: es_repo_name: "{{ 'oss-' + es_major_version }}" + es_other_repo_name: "{{ es_major_version }}" es_package_name: "elasticsearch-oss" es_other_package_name: "elasticsearch" when: diff --git a/tasks/elasticsearch-RedHat.yml b/tasks/elasticsearch-RedHat.yml index d002991..190adc3 100644 --- a/tasks/elasticsearch-RedHat.yml +++ b/tasks/elasticsearch-RedHat.yml @@ -13,7 +13,16 @@ - name: RedHat - add Elasticsearch repo become: yes - template: src=elasticsearch.repo dest=/etc/yum.repos.d/elasticsearch-{{ es_repo_name }}.repo + template: + src: 'elasticsearch.repo' + dest: '/etc/yum.repos.d/elasticsearch-{{ es_repo_name }}.repo' + when: es_use_repository + +- name: RedHat - remove unused Elasticsearch repo + become: yes + template: + src: 'elasticsearch.repo' + dest: '/etc/yum.repos.d/elasticsearch-{{ es_other_repo_name }}.repo' when: es_use_repository - name: RedHat - include versionlock From 5126dbc5e8fe7364e7b3a2c30e66c132e3966108 Mon Sep 17 00:00:00 2001 From: Michael Russell Date: Wed, 2 Jan 2019 10:06:47 +0100 Subject: [PATCH 05/11] Actually remove the unused RedHat repository --- tasks/elasticsearch-RedHat.yml | 6 ++--- .../helpers/serverspec/shared_spec.rb | 25 +++++++++++++++++++ 2 files changed, 28 insertions(+), 3 deletions(-) diff --git a/tasks/elasticsearch-RedHat.yml b/tasks/elasticsearch-RedHat.yml index 190adc3..c872fc3 100644 --- a/tasks/elasticsearch-RedHat.yml +++ b/tasks/elasticsearch-RedHat.yml @@ -20,9 +20,9 @@ - name: RedHat - remove unused Elasticsearch repo become: yes - template: - src: 'elasticsearch.repo' - dest: '/etc/yum.repos.d/elasticsearch-{{ es_other_repo_name }}.repo' + file: + path: '/etc/yum.repos.d/elasticsearch-{{ es_other_repo_name }}.repo' + state: absent when: es_use_repository - name: RedHat - include versionlock diff --git a/test/integration/helpers/serverspec/shared_spec.rb b/test/integration/helpers/serverspec/shared_spec.rb index d707cde..eca6682 100644 --- a/test/integration/helpers/serverspec/shared_spec.rb +++ b/test/integration/helpers/serverspec/shared_spec.rb @@ -167,4 +167,29 @@ shared_examples 'shared::init' do |vars| its(:content) { should match "path.data: #{vars['data_dirs'].join(',')}" } its(:content) { should match "path.logs: /var/log/elasticsearch/localhost-#{vars['es_instance_name']}" } end + + if vars['es_use_repository'] + if vars['ansible_os_family'] == 'RedHat' + describe file("/etc/yum.repos.d/elasticsearch-#{vars['es_repo_name']}.repo") do + it { should exist } + end + describe yumrepo("elasticsearch-#{vars['es_repo_name']}") do + it { should exist } + it { should be_enabled } + end + describe file("/etc/yum.repos.d/elasticsearch-#{vars['es_other_repo_name']}.repo") do + it { should_not exist } + end + describe yumrepo("elasticsearch-#{vars['es_other_repo_name']}") do + it { should_not exist } + it { should_not be_enabled } + end + end + if vars['ansible_os_family'] == 'Debian' + describe command('apt-cache policy') do + its(:stdout) { should match /elastic.co.*\/#{Regexp.quote(vars['es_repo_name'])}\//} + its(:stdout) { should_not match /elastic.co.*\/#{Regexp.quote(vars['es_other_repo_name'])}\//} + end + end + end end From f7d402369c4185bed3c4b909afb310e22ec578fc Mon Sep 17 00:00:00 2001 From: Michael Russell Date: Wed, 2 Jan 2019 10:39:48 +0100 Subject: [PATCH 06/11] Properly cleanup the other apt repository when switching packages --- tasks/compatibility-variables.yml | 2 ++ tasks/elasticsearch-Debian.yml | 47 +++++++++++++++++-------------- 2 files changed, 28 insertions(+), 21 deletions(-) diff --git a/tasks/compatibility-variables.yml b/tasks/compatibility-variables.yml index 2116dfd..0907ad2 100644 --- a/tasks/compatibility-variables.yml +++ b/tasks/compatibility-variables.yml @@ -16,6 +16,7 @@ es_xpack_users_command: "elasticsearch-users" es_other_package_name: "elasticsearch-oss" es_other_repo_name: "{{ 'oss-' + es_major_version }}" + es_other_apt_url: "deb https://artifacts.elastic.co/packages/{{ 'oss-' + es_major_version }}/apt stable main" - name: Detect if es_version is before X-Pack was open and included set_fact: @@ -35,6 +36,7 @@ set_fact: es_repo_name: "{{ 'oss-' + es_major_version }}" es_other_repo_name: "{{ es_major_version }}" + es_other_apt_url: "deb https://artifacts.elastic.co/packages/{{ es_major_version }}/apt stable main" es_package_name: "elasticsearch-oss" es_other_package_name: "elasticsearch" when: diff --git a/tasks/elasticsearch-Debian.yml b/tasks/elasticsearch-Debian.yml index 680f654..2739e51 100644 --- a/tasks/elasticsearch-Debian.yml +++ b/tasks/elasticsearch-Debian.yml @@ -7,26 +7,8 @@ set_fact: force_install=yes when: es_allow_downgrades -- name: Debian - Install apt-transport-https to support https APT downloads - become: yes - apt: name=apt-transport-https state=present - when: es_use_repository - -- name: Debian - Add Elasticsearch repository key - become: yes - apt_key: url="{{ es_apt_key }}" state=present - when: es_use_repository and es_apt_key - -- name: Debian - Add elasticsearch repository - become: yes - apt_repository: repo={{ item.repo }} state={{ item.state}} - with_items: - - { repo: "{{ es_apt_url_old }}", state: "absent" } - - { repo: "{{ es_apt_url }}", state: "present" } - when: es_use_repository - - - name: Gracefully stop and remove elasticsearch package if switching between OSS and standard + become: yes block: - name: Check if the elasticsearch package is installed shell: "dpkg-query -W -f'${Status}' {{ es_other_package_name }}" @@ -35,20 +17,43 @@ changed_when: False - name: stop elasticsearch - become: yes service: name: '{{ instance_init_script | basename }}' state: stopped when: elasticsearch_package.stdout == 'install ok installed' - name: Debian - Remove elasticsearch package if we are switching to a different package type - become: yes apt: name: '{{ es_other_package_name }}' state: absent when: elasticsearch_package.stdout == 'install ok installed' +- name: Install Elasticsearch repository + when: es_use_repository + become: yes + block: + - name: Debian - Install apt-transport-https to support https APT downloads + apt: + name: apt-transport-https + state: present + + - name: Debian - Add Elasticsearch repository key + apt_key: + url: '{{ es_apt_key }}' + state: present + when: es_apt_key is defined + + - name: Debian - Add elasticsearch repository + apt_repository: + repo: '{{ item.repo }}' + state: '{{ item.state }}' + with_items: + - { repo: "{{ es_apt_url_old }}", state: "absent" } + - { repo: "{{ es_apt_url }}", state: "present" } + - { repo: "{{ es_other_apt_url }}", state: "absent" } + + - name: Debian - Ensure elasticsearch is installed become: yes apt: From 596f313b170ee372188ac851036eceebae76bd9c Mon Sep 17 00:00:00 2001 From: Frank Fischer Date: Mon, 14 Jan 2019 11:24:32 +0100 Subject: [PATCH 07/11] Allow not installing Elasticsearch deb repository key If a variable is set in Ansible, there is no way to unset it ever again, i.e. 'null' or '~' do not work. Since this value is set in defaults we have to check for content instead of defined. --- tasks/elasticsearch-Debian.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tasks/elasticsearch-Debian.yml b/tasks/elasticsearch-Debian.yml index 41a2256..7b9a735 100644 --- a/tasks/elasticsearch-Debian.yml +++ b/tasks/elasticsearch-Debian.yml @@ -42,7 +42,7 @@ apt_key: url: '{{ es_apt_key }}' state: present - when: es_apt_key is defined + when: es_apt_key | string - name: Debian - Add elasticsearch repository apt_repository: From 5d0dcbe147d294add938f864f6a7c0fdeb908af3 Mon Sep 17 00:00:00 2001 From: "shin.katsumaru" Date: Tue, 15 Jan 2019 17:19:02 +0900 Subject: [PATCH 08/11] Execute java version check in check mode --- tasks/java.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/tasks/java.yml b/tasks/java.yml index a7174da..68abc53 100644 --- a/tasks/java.yml +++ b/tasks/java.yml @@ -18,6 +18,7 @@ register: java_full_path failed_when: False changed_when: False + check_mode: no when: ansible_os_family == 'RedHat' - name: correct java version selected From fd8ea77fa483e889e580f3ecb6e90f7168d6f0fb Mon Sep 17 00:00:00 2001 From: Frank Fischer Date: Mon, 14 Jan 2019 15:53:01 +0100 Subject: [PATCH 09/11] Use systemd's RequiresMountsFor User might be interested in separating data in ephemeral and persistent state, especially in cloud environments, e.g. data_dir on another disk. --- templates/systemd/elasticsearch.j2 | 2 ++ 1 file changed, 2 insertions(+) diff --git a/templates/systemd/elasticsearch.j2 b/templates/systemd/elasticsearch.j2 index 8bd5545..79fe382 100644 --- a/templates/systemd/elasticsearch.j2 +++ b/templates/systemd/elasticsearch.j2 @@ -3,6 +3,8 @@ Description=Elasticsearch-{{es_instance_name}} Documentation=http://www.elastic.co Wants=network-online.target After=network-online.target +{# Directive 'WorkingDirectory' creates an implicit dependecy for {{es_home}}, so it can be omitted here #} +RequiresMountsFor={{ data_dirs | array_to_str(separator=' ') }} {{log_dir}} {{pid_dir}} {{conf_dir}} [Service] Environment=ES_HOME={{es_home}} From 2d7bc5607eb708476afac7034c5a705e2da63687 Mon Sep 17 00:00:00 2001 From: Lilian Deloche Date: Thu, 24 Jan 2019 15:30:49 +0100 Subject: [PATCH 10/11] Use dpkg_selections to lock elasticsearch version --- tasks/elasticsearch-Debian-version-lock.yml | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/tasks/elasticsearch-Debian-version-lock.yml b/tasks/elasticsearch-Debian-version-lock.yml index 4ca9b24..6d52493 100644 --- a/tasks/elasticsearch-Debian-version-lock.yml +++ b/tasks/elasticsearch-Debian-version-lock.yml @@ -1,6 +1,6 @@ --- - name: Debian - hold elasticsearch version become: yes - command: "apt-mark hold {{ es_package_name }}" - register: hold_elasticsearch_result - changed_when: "hold_elasticsearch_result.stdout != '{{ es_package_name }} was already set on hold.'" + dpkg_selections: + name: "{{ es_package_name }}" + selection: "hold" From f169a434d8da84805506437cc54e4ee161dc9b11 Mon Sep 17 00:00:00 2001 From: Michael Russell Date: Tue, 29 Jan 2019 17:13:59 +0100 Subject: [PATCH 11/11] Bump default version to 6.6.0 --- CHANGELOG.md | 16 ++++++++++++++++ defaults/main.yml | 2 +- 2 files changed, 17 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 7e75d7a..df21779 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,19 @@ +## 6.6.0 - 2019/01/29 + +### Features + +* 6.6.0 as default Elasticsearch version +* [#521](https://github.com/elastic/ansible-elasticsearch/pull/521) - @Crazybus - Allow switching between oss and standard packages +* [#528](https://github.com/elastic/ansible-elasticsearch/pull/528) - @Fra-nk - Use systemd's RequiresMountsFor +* [#530](https://github.com/elastic/ansible-elasticsearch/pull/530) - @lde - Use dpkg_selections to lock elasticsearch version + +### Fixes + +* [#513](https://github.com/elastic/ansible-elasticsearch/pull/513) - @kakoni - Fix typo in elasticsearch-parameters.yml +* [#522](https://github.com/elastic/ansible-elasticsearch/pull/522) - @SlothOfAnarchy - Fix package download URL +* [#526](https://github.com/elastic/ansible-elasticsearch/pull/527) - @Fra-nk - Allow not installing Elasticsearch deb repository key +* [#527](https://github.com/elastic/ansible-elasticsearch/pull/527) - @katsukamaru - Execute java version check in check mode + ## 6.5.1.1 - 2018/11/27 ### Fixes diff --git a/defaults/main.yml b/defaults/main.yml index f9f140b..1aac16d 100644 --- a/defaults/main.yml +++ b/defaults/main.yml @@ -1,6 +1,6 @@ --- es_major_version: "6.x" -es_version: "6.5.1" +es_version: "6.6.0" es_use_snapshot_release: false es_enable_xpack: true es_package_name: "elasticsearch"