From: Guillaume Thouvenin Date: Thu, 17 Nov 2016 09:49:58 +0000 (+0100) Subject: Add an Elasticsearch client X-Git-Tag: 2016.12~5^2~11^2 X-Git-Url: https://gerrit.mcp.mirantis.com/gitweb?p=salt-formulas%2Felasticsearch.git;a=commitdiff_plain;h=d39b35210140948c5f1f5bfa40d8971f21f2124e Add an Elasticsearch client This patch adds a client. The client will be responsible to push new indexes and new templates to Elasticsearch. --- diff --git a/README.rst b/README.rst index 7e9ccce..1d85c54 100644 --- a/README.rst +++ b/README.rst @@ -119,6 +119,20 @@ Common definition for curator: unit: days unit_count: 2 +Client setup +------------ + +Client with host and port + +.. code-block:: yaml + + elasticsearch: + client: + enabled: true + server: + host: elasticsearch.host + port: 9200 + Read more ========= diff --git a/elasticsearch/client.sls b/elasticsearch/client.sls new file mode 100644 index 0000000..bc14f82 --- /dev/null +++ b/elasticsearch/client.sls @@ -0,0 +1,11 @@ +{%- from "elasticsearch/map.jinja" import client with context %} +{%- if client.get('enabled', False) %} + +/etc/salt/minion.d/_elasticsearch.conf: + file.managed: + - source: salt://elasticsearch/files/_elasticsearch.conf + - template: jinja + - user: root + - group: root + +{%- endif %} diff --git a/elasticsearch/files/_elasticsearch.conf b/elasticsearch/files/_elasticsearch.conf new file mode 100644 index 0000000..0a555bc --- /dev/null +++ b/elasticsearch/files/_elasticsearch.conf @@ -0,0 +1,4 @@ +{%- from "elasticsearch/map.jinja" import client with context %} + +elasticsearch: + host: {{client.server.host}}:{{client.server.port}} diff --git a/elasticsearch/init.sls b/elasticsearch/init.sls index fadf2bf..d6078be 100644 --- a/elasticsearch/init.sls +++ b/elasticsearch/init.sls @@ -1,5 +1,10 @@ -{% if pillar.elasticsearch.server is defined %} +{%- if pillar.elasticsearch is defined %} include: +{%- if pillar.elasticsearch.server is defined %} - elasticsearch.server -{% endif %} +{%- endif %} +{%- if pillar.elasticsearch.client is defined %} +- elasticsearch.client +{%- endif %} +{%- endif %} diff --git a/elasticsearch/map.jinja b/elasticsearch/map.jinja index 000a1f4..e2d7871 100644 --- a/elasticsearch/map.jinja +++ b/elasticsearch/map.jinja @@ -18,3 +18,12 @@ RedHat: {%- endload %} {%- set server = salt['grains.filter_by'](base_defaults, merge=salt['pillar.get']('elasticsearch:server')) %} + +{%- load_yaml as client_defaults %} +default: + server: + host: 127.0.0.1 + port: 9200 +{%- endload %} + +{%- set client = salt['grains.filter_by'](client_defaults, merge=salt['pillar.get']('elasticsearch:client')) %} diff --git a/metadata/service/client.yml b/metadata/service/client.yml new file mode 100644 index 0000000..1e5fbc1 --- /dev/null +++ b/metadata/service/client.yml @@ -0,0 +1,6 @@ +applications: +- elasticsearch.client +parameters: + elasticsearch: + client: + enabled: true