From: Dmitry Kalashnik Date: Tue, 20 Feb 2018 15:17:55 +0000 (+0400) Subject: Add state for updating Elasticsearch index templates X-Git-Url: https://gerrit.mcp.mirantis.com/gitweb?p=salt-formulas%2Felasticsearch.git;a=commitdiff_plain;h=refs%2Fchanges%2F11%2F16011%2F6 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 --- 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 %}