From 8e0029b8d5dfed0a8e797f30c6cbc1993b4d542e Mon Sep 17 00:00:00 2001 From: Dmitry Kalashnik Date: Tue, 20 Feb 2018 19:17:55 +0400 Subject: [PATCH] Add state for updating Elasticsearch index templates To prevent index template from constant or accidential update add separate salt state to explicit use in order to update. To use run: salt -C 'I@elasticsearch:client' state.sls elasticsearch.client.update_index_templates Change-Id: I19aca3c6901f79ac22457a30aada0904057de5cc Closes-Bug: PROD-17954 --- README.rst | 9 ++++++ .../client/update_index_templates.sls | 31 +++++++++++++++++++ 2 files changed, 40 insertions(+) create mode 100644 elasticsearch/client/update_index_templates.sls diff --git a/README.rst b/README.rst index eb8a67b..a117a0b 100644 --- a/README.rst +++ b/README.rst @@ -192,6 +192,15 @@ Client where you download an index template from the metadata definition and for type: keyword ignore_above: 256 +Upgrade operations +------------------ + +Default elasticsearch client state can only create index temlates. To update exisiting ones according to pillar dedicated state should be run explicitly: + +.. code-block:: bash + + salt -C 'I@elasticsearch:client' state.sls elasticsearch.client.update_index_templates + Read more ========= diff --git a/elasticsearch/client/update_index_templates.sls b/elasticsearch/client/update_index_templates.sls new file mode 100644 index 0000000..88c8e64 --- /dev/null +++ b/elasticsearch/client/update_index_templates.sls @@ -0,0 +1,31 @@ +{%- from "elasticsearch/map.jinja" import client with context %} +{%- if client.get('enabled', False) %} + +include: + - elasticsearch.client.service + +{%- for index_name, index in client.get('index', {}).iteritems() %} +elasticsearch_index_template_upgrade_{{ index_name }}: + + {%- if index.get('enabled', False) %} + + {%- if index.definition is defined %} + {% set definition = index.definition %} + {%- endif %} + {%- if index.template is defined %} + {%- import_json index.template as definition %} + {%- endif %} + + {%- if definition is defined %} + module.run: + - name: elasticsearch.index_template_create + - m_name: {{ index_name }} + - body: '{{ definition|json }}' + - require: + - pkg: elasticsearch_client_packages + {%- endif %} + + {%- endif %} + +{%- endfor %} +{%- endif %} -- 2.32.7