Skip to content
This repository has been archived by the owner on Jun 24, 2022. It is now read-only.

Commit

Permalink
Abstract 6.3 changes into a separate task to reduce all of the jinja one
Browse files Browse the repository at this point in the history
liner complexity

Set ES_PATH_CONF when installing so upgrading from 6.2 to 6.3 works as
expected
  • Loading branch information
Crazybus committed Jun 14, 2018
1 parent 715bd85 commit bbc5e06
Show file tree
Hide file tree
Showing 9 changed files with 52 additions and 13 deletions.
4 changes: 1 addition & 3 deletions .kitchen.yml
Expand Up @@ -21,9 +21,7 @@ provisioner:
extra_vars:
es_major_version: "<%= ENV['VERSION'] %>"
<% if ENV['VERSION'] == '5.x' %>
es_version: '5.6.9'
es_package_name: 'elasticsearch'
es_use_snapshot_release: false
es_version: '5.6.10'
<% end %>
<% end %>

Expand Down
35 changes: 35 additions & 0 deletions tasks/compatibility-variables.yml
@@ -0,0 +1,35 @@
---

# It is possible to set these are defaults with messy jinja templating one liners however:
# 1. That is really hard to read and debug
# 2. When running multiple plays with the same role the defaults are not re-evaluated. An example of this
# can be seen in our the https://github.com/elastic/ansible-elasticsearch/blob/master/test/integration/xpack.yml
# integration test and in the Multi Node server documentation examples https://github.com/elastic/ansible-elasticsearch/blob/master/test/integration/xpack.yml

- name: Set the defaults here otherwise they can't be overriden in the same play if the role is called twice
set_fact:
es_open_xpack: true
es_install_xpack: false
es_repo_name: "{{ es_major_version }}"
es_xpack_users_command: "elasticsearch-users"

- name: Detect if es_version is before X-Pack was open and included
set_fact:
es_open_xpack: false
when: "es_version | version_compare('6.3.0', '<')"

- name: If this is an older version we need to install X-Pack as a plugin and use a differet users command
set_fact:
es_install_xpack: true
es_xpack_users_command: "x-pack/users"
when:
- not es_open_xpack
- es_enable_xpack

- name: Use the oss repo and package if xpack is not being used
set_fact:
es_repo_name: "{{ 'oss-' + es_major_version }}"
es_package_name: "elasticsearch-oss"
when:
- es_open_xpack
- not es_enable_xpack
2 changes: 2 additions & 0 deletions tasks/elasticsearch-Debian.yml
Expand Up @@ -36,6 +36,8 @@
when: es_use_repository
register: debian_elasticsearch_install_from_repo
notify: restart elasticsearch
environment:
ES_PATH_CONF: "/etc/elasticsearch"

- name: Debian - Include versionlock
include: elasticsearch-Debian-version-lock.yml
Expand Down
2 changes: 2 additions & 0 deletions tasks/elasticsearch-RedHat.yml
Expand Up @@ -25,6 +25,8 @@
until: redhat_elasticsearch_install_from_repo.rc == 0
retries: 5
delay: 10
environment:
ES_PATH_CONF: "/etc/elasticsearch"

- name: RedHat - Install Elasticsearch from url
become: yes
Expand Down
5 changes: 5 additions & 0 deletions tasks/main.yml
Expand Up @@ -4,6 +4,11 @@
tags:
- always

- name: set compatibility variables
include: compatibility-variables.yml
tags:
- always

- name: check-set-parameters
include: elasticsearch-parameters.yml
tags:
Expand Down
8 changes: 4 additions & 4 deletions tasks/xpack/security/elasticsearch-security-file.yml
Expand Up @@ -18,7 +18,7 @@
- name: Remove Users
become: yes
command: >
{{es_home}}/bin/x-pack/users userdel {{item}}
{{es_home}}/bin/{{es_xpack_users_command}} userdel {{item}}
with_items: "{{users_to_remove | default([])}}"
when: manage_file_users
environment:
Expand All @@ -34,7 +34,7 @@
- name: Add Users
become: yes
command: >
{{es_home}}/bin/x-pack/users useradd {{item}} -p {{es_users.file[item].password}}
{{es_home}}/bin/{{es_xpack_users_command}} useradd {{item}} -p {{es_users.file[item].password}}
with_items: "{{ users_to_add | default([]) }}"
when: manage_file_users
no_log: True
Expand All @@ -47,12 +47,12 @@
- name: Set User Passwords
become: yes
command: >
{{es_home}}/bin/x-pack/users passwd {{ item }} -p {{es_users.file[item].password}}
{{es_home}}/bin/{{es_xpack_users_command}} passwd {{ item }} -p {{es_users.file[item].password}}
with_items: "{{ es_users.file.keys() | default([]) }}"
when: manage_file_users
#Currently no easy way to figure out if the password has changed or to know what it currently is so we can skip.
changed_when: False
no_log: True
no_log: False
environment:
CONF_DIR: "{{ conf_dir }}"
ES_PATH_CONF: "{{ conf_dir }}"
Expand Down
3 changes: 2 additions & 1 deletion tasks/xpack/security/elasticsearch-security.yml
Expand Up @@ -19,7 +19,8 @@
- name: create the keystore if it doesn't exist yet
command: >
{{es_home}}/bin/elasticsearch-keystore create
creates: "{{ conf_dir }}/elasticsearch.keystore"
args:
creates: "{{ conf_dir }}/elasticsearch.keystore"
environment:
ES_PATH_CONF: "{{ conf_dir }}"

Expand Down
2 changes: 1 addition & 1 deletion test/integration/xpack.yml
Expand Up @@ -10,7 +10,7 @@
vars:
es_heap_size: "1g"
es_templates: true
es_version: "{{ '6.2.4' if es_major_version == '6.x' else '5.6.6' }}" # This is set to an older version than the current default to force an upgrade
es_version: "{{ '6.2.4' if es_major_version == '6.x' else '5.6.9' }}" # This is set to an older version than the current default to force an upgrade
es_enable_xpack: true
es_xpack_license: "{{ lookup('file', '/tmp/license.json') }}"
es_plugins:
Expand Down
4 changes: 0 additions & 4 deletions vars/main.yml
Expand Up @@ -6,7 +6,3 @@ init_script: "/etc/init.d/elasticsearch"
#add supported features here
supported_xpack_features: ["alerting","monitoring","graph","security"]
reserved_xpack_users: ["elastic","kibana","logstash_system"]

# X-Pack used to be installed as a plugin. For versions after 6.3 we don't need to install it anymore
es_install_xpack: "{{ true if ( es_version | version_compare('6.3.0', '<')) else false }}"
es_repo_name: "{{ 'oss-' + es_major_version if (( es_version | version_compare('6.3.0', '>=')) and not es_enable_xpack ) else es_major_version }}"

0 comments on commit bbc5e06

Please sign in to comment.