From 85afac96ea7bb109f4d39e41acadb1afb509493b Mon Sep 17 00:00:00 2001 From: Greg Rundlett Date: Sat, 2 Nov 2024 18:06:19 +0000 Subject: [PATCH] Remove Elasticsearch upgrade playbook Issue #118 --- src/playbooks/elasticsearch-upgrade.yml | 118 ---------------- src/roles/elasticsearch/tasks/es_upgrade.yml | 138 ------------------- src/roles/elasticsearch/tasks/main.yml | 61 +------- 3 files changed, 1 insertion(+), 316 deletions(-) delete mode 100644 src/playbooks/elasticsearch-upgrade.yml delete mode 100644 src/roles/elasticsearch/tasks/es_upgrade.yml diff --git a/src/playbooks/elasticsearch-upgrade.yml b/src/playbooks/elasticsearch-upgrade.yml deleted file mode 100644 index bb9ab389..00000000 --- a/src/playbooks/elasticsearch-upgrade.yml +++ /dev/null @@ -1,118 +0,0 @@ ---- -# Ansible -# Rolling Upgrade of Elasticsearch -# Original author: Jeff Steinmetz, @jeffsteinmetz -# Original URL: https://github.com/ekhoinc/ansible-examples/blob/master/elasticsearch-rolling-upgrade.yml -# Adapted for meza by James Montalvo, @jamesmontalvo3 - -# Per the 2.x docs [1] upgrading from 1.x requires a "full cluster restart" -# Per the "full cluster restart" docs [2] - -# [1] https://www.elastic.co/guide/en/elasticsearch/reference/2.3/setup-upgrade.html -# -- name: Elasticsearch rolling upgrade - # At Ekho, we use Amazon tags liberally to track production vs development - # as well as a tag that lists the Services each server hosts. - # Modify hosts to match your inventory group strategy. - # such as: - # hosts: tag_Services_elasticsearch:&tag_Environment_production - hosts: search - serial: 1 - become: true - - vars: - es_disable_allocation: '{"transient":{"cluster.routing.allocation.enable":"none"}}' - es_enable_allocation: '{"transient":{"cluster.routing.allocation.enable": "all"}}' - es_http_port: 9200 - es_transport_port: 9300 - # desired version to upgrade to: - es_version: 1.4.3 - - tasks: - # this first step is a overkill, but here - # in case the upgrade was cancelled by user mid playbook run - - name: make sure elasticsearch service is running - service: name=elasticsearch enabled=yes state=started - register: response - - - name: Wait for elasticsearch node to come back up if it was stopped - wait_for: port={{ es_transport_port }} delay=45 - when: response.changed == true - - # the ansible the uri action needs httplib2 - - name: ensure python-httplib2 is installed - apt: name=python-httplib2 state=present - - - name: check current version - uri: url=http://localhost:{{ es_http_port }} method=GET - register: version_found - retries: 10 - delay: 10 - - - name: Display Current Elasticsearch Version - ansible.builtin.debug: var=version_found.json.version.number - - # this step is key!!! Don't restart more nodes - # until all shards have completed recovery - - name: Wait for cluster health to return to green - uri: url=http://localhost:{{ es_http_port }}/_cluster/health method=GET - register: response - until: "response.json.status == 'green'" - retries: 50 - delay: 30 - when: version_found.json.version.number != '{{ es_version }}' - - - name: Disable shard allocation for the cluster - uri: url=http://localhost:{{ es_http_port }}/_cluster/settings method=PUT body='{{ es_disable_allocation }}' - when: version_found.json.version.number != '{{ es_version }}' - - - name: Shutdown elasticsearch node - uri: url=http://localhost:{{ es_http_port }}/_cluster/nodes/_local/_shutdown method=POST - when: version_found.json.version.number != '{{ es_version }}' - - - name: Wait for all shards to be reallocated - uri: url=http://localhost:{{ es_http_port }}/_cluster/health method=GET - register: response - until: "response.json.relocating_shards == 0" - retries: 10 - delay: 30 - when: version_found.json.version.number != '{{ es_version }}' - - # this is specific to Ubuntu / Debian based distributions - - name: Download Elasticsearch version - get_url: url=https://download.elasticsearch.org/elasticsearch/elasticsearch/elasticsearch-{{ es_version }}.deb dest=/tmp/elasticsearch-{{ es_version }}.deb - when: version_found.json.version.number != '{{ es_version }}' - - - name: Update elasticsearch - apt: deb=/tmp/elasticsearch-{{ es_version }}.deb - when: version_found.json.version.number != '{{ es_version }}' - - - name: clean temp file - file: path=/tmp/elasticsearch-{{ es_version }}.deb state=absent - when: version_found.json.version.number != '{{ es_version }}' - - - name: Start elasticsearch - service: name=elasticsearch enabled=yes state=restarted - when: version_found.json.version.number != '{{ es_version }}' - - - name: Wait for elasticsearch node to come back up - wait_for: port={{ es_transport_port }} delay=35 - when: version_found.json.version.number != '{{ es_version }}' - - - name: Wait for cluster health to return to yellow or green - uri: url=http://localhost:{{ es_http_port }}/_cluster/health method=GET - register: response - until: "response.json.status == 'yellow' or response.json.status == 'green'" - retries: 5 - delay: 30 - when: version_found.json.version.number != '{{ es_version }}' - - - name: Enable shard allocation for the cluster - uri: url=http://localhost:{{ es_http_port }}/_cluster/settings method=PUT body='{{ es_enable_allocation }}' - register: response - # next line is boolean not string, so no quotes around true - # use python truthiness - until: "response.json.acknowledged == true" - retries: 5 - delay: 30 - when: version_found.json.version.number != '{{ es_version }}' diff --git a/src/roles/elasticsearch/tasks/es_upgrade.yml b/src/roles/elasticsearch/tasks/es_upgrade.yml deleted file mode 100644 index 8c34b442..00000000 --- a/src/roles/elasticsearch/tasks/es_upgrade.yml +++ /dev/null @@ -1,138 +0,0 @@ ---- -# Ansible -# Rolling Upgrade of Elasticsearch -# Original author: Jeff Steinmetz, @jeffsteinmetz -# Original URL: https://github.com/ekhoinc/ansible-examples/blob/master/elasticsearch-rolling-upgrade.yml -# Adapted for meza by James Montalvo, @jamesmontalvo3 - -# Per the 2.x docs [1] upgrading from 1.x requires a "full cluster restart" -# Per the "full cluster restart" docs [2] - -# [1] https://www.elastic.co/guide/en/elasticsearch/reference/2.3/setup-upgrade.html - - -# Upgrades will likely require new plugin versions. Remove plugins which were -# once installed by meza. Any user-installed plugins will need to be manually -# removed unless we come up with a way to remove all. -# -# Removing elasticsearch plugins. They're too much work to keep in sync with -# Elasticsearch, and anyone who wants (and knows how) to use them can install -# them manually. -- name: Ensure elasticsearch plugins removed - shell: "/usr/share/elasticsearch/bin/plugin remove {{ item }}" - failed_when: False - with_items: - - bigdesk - - head - - kopf - -# This step is key!!! Don't restart more nodes until all shards have completed -# recovery -# Perhaps not required if doing a full restart -# - name: Wait for cluster health to return to green -# uri: -# url: "http://localhost:{{ elasticsearch_http_port }}/_cluster/health" -# method: GET -# register: response -# until: "response.json.status == 'green'" -# retries: 50 -# delay: 30 - - -# FIXME: Maybe add step to tell MediaWiki to trying to use Elasticsearch, in -# particular if this is a single ES node setup. Either way, having MW -# attempt to add to the index may be bad. - - -- name: Disable shard allocation for the cluster - uri: - url: "http://localhost:{{ elasticsearch_http_port }}/_cluster/settings" - method: PUT - body: "{{ elasticsearch_disable_allocation | string }}" - -# Ref: https://www.elastic.co/guide/en/elasticsearch/reference/2.4/restart-upgrade.html#_step_2_perform_a_synced_flush -# Ref: https://www.elastic.co/guide/en/elasticsearch/reference/2.4/indices-synced-flush.html -- name: Perform synced flush - uri: - url: "http://localhost:{{ elasticsearch_http_port }}/_flush/synced" - method: POST - -# Shutdown all nodes -- name: Shutdown elasticsearch node - service: - name: elasticsearch - state: stopped - - -# For a rolling upgrade: -# If the above command shuts down elasticsearch, how is this hitting the -# Elasticsearch API? It definitely cannot be hitting anything if this ES -# node is the only ES node. As such, the "when" clause to skip this when -# number of ES servers is 1 has been added. The FIXME is that we need to -# actually test this in a multi-node setup. -# - name: Wait for all shards to be reallocated -# uri: -# url: "http://localhost:{{ elasticsearch_http_port }}/_cluster/health" -# method: GET -# register: response -# until: "response.json.relocating_shards == 0" -# retries: 10 -# delay: 30 -# when: "groups['elastic_servers']|length|int > 1" - -- name: Ensure Elasticsearch is latest version - yum: - lock_timeout: 180 # wait up to 3 minutes for a lock ansible/ansible#57189 - name: elasticsearch - state: latest - -- name: Start elasticsearch - service: - name: elasticsearch - enabled: true - state: restarted - daemon_reload: true - -- name: Wait for elasticsearch node to come back up - wait_for: - port: "{{ elasticsearch_transport_port }}" - delay: 35 - -- name: Wait for cluster health to return to yellow or green - uri: - url: "http://localhost:{{ elasticsearch_http_port }}/_cluster/health" - method: GET - register: response - until: "response.json.status == 'yellow' or response.json.status == 'green'" - retries: 5 - delay: 30 - -- name: Enable shard allocation for the cluster - uri: - url: "http://localhost:{{ elasticsearch_http_port }}/_cluster/settings" - method: PUT - body: "{{ elasticsearch_enable_allocation | string }}" - body_format: json - register: response - # next line is boolean not string, so no quotes around true - # use python truthiness - until: "response.json.acknowledged == true" - retries: 5 - delay: 30 - - -# -# No re-display Elasticsearch version -# -- name: Check current Elasticsearch version - uri: - url: "http://localhost:{{ elasticsearch_http_port }}" - method: GET - register: version_found - retries: 10 - delay: 10 - -- name: Re-display current Elasticsearch full version number after upgrade - ansible.builtin.debug: - var: version_found.json.version.number - diff --git a/src/roles/elasticsearch/tasks/main.yml b/src/roles/elasticsearch/tasks/main.yml index 3bb6d30d..d8bce8b8 100644 --- a/src/roles/elasticsearch/tasks/main.yml +++ b/src/roles/elasticsearch/tasks/main.yml @@ -17,7 +17,7 @@ state: present # Environment setup. -- name: Set JAVA_HOME if configured. +- name: Set JAVA_HOME if configured. template: src: java_home.sh.j2 dest: /etc/profile.d/java_home.sh @@ -123,62 +123,3 @@ delay: 3 timeout: 300 when: docker_skip_tasks is not defined or not docker_skip_tasks - - -# Previously, elasticsearch plugins Head and Kopf (and at one time Bigdesk and -# Inquisitor) were installed here. - - -# -# Perform checks on Elasticsearch version -# -- name: Check current Elasticsearch version - uri: - url: "http://localhost:{{ elasticsearch_http_port }}" - method: GET - # user: "{{ elasticsearch_username }}" - # password: "{{ elasticsearch_password }}" - register: version_found - retries: 10 - delay: 10 - when: docker_skip_tasks is not defined or not docker_skip_tasks - -- name: Display current Elasticsearch full version number - ansible.builtin.debug: - var: version_found.json.version.number - when: docker_skip_tasks is not defined or not docker_skip_tasks - -- name: Display desired Elasticsearch version - ansible.builtin.debug: - var: elasticsearch_major_version - -- name: Set the Elasticsearch major version found - set_fact: - es_version_found: "{{ version_found.json.version.number | list | first }}" - when: docker_skip_tasks is not defined or not docker_skip_tasks - -- name: "Docker image building only: set found version to desired version" - set_fact: - es_version_found: "{{ elasticsearch_major_version | list | first }}" - when: docker_skip_tasks is defined and docker_skip_tasks - -- name: Set the Elasticsearch major version desired - set_fact: - es_version_desired: "{{ elasticsearch_major_version | list | first }}" - -# Do false first. Then force_do_elasticsearch_upgrade can override -- name: Set do_elasticsearch_upgrade to FALSE - set_fact: - do_elasticsearch_upgrade: False - when: es_version_found|int == es_version_desired|int - -# Note: force_do_elasticsearch_upgrade not set anywhere. This can be used with: -# `meza deploy ... --extra-vars "force_do_elasticsearch_upgrade=True"` -- name: Set do_elasticsearch_upgrade to TRUE - set_fact: - do_elasticsearch_upgrade: True - when: (es_version_found|int != es_version_desired|int) or (force_do_elasticsearch_upgrade is defined and force_do_elasticsearch_upgrade) - -- name: Include upgrade tasks for ES 5.x --> 6.x - include_tasks: es_upgrade.yml - when: do_elasticsearch_upgrade