diff --git a/consul/files/services.json b/consul/files/services.json index d40bd01..b4238c0 100644 --- a/consul/files/services.json +++ b/consul/files/services.json @@ -1,24 +1,6 @@ {% from "consul/map.jinja" import consul with context %} { - "services": [ - {% for service in consul.register %} - { - {% for key, value in service.items() %} - {% if key == 'checks' %} - "checks": [ - {% for key2, value2 in value.items() %} - {% if key2 == 'script' %} - "script": /opt/consul/scripts/{{ value2.split('/')[-1] }}{% if not loop.last %},{% endif %} - {% else %} - "{{ key2 }}": {{ value2 | json}}{% if not loop.last %},{% endif %} - {% endif %} - {% endfor %} - ]{% if not loop.last %},{% endif %} - {% else %} - "{{ key }}": {{ value | json}}{% if not loop.last %},{% endif %} - {% endif %} - {% endfor %} - }{% if not loop.last %},{% endif %} - {% endfor %} - ] + "services": { + {% consul.register | json %} + } } diff --git a/consul/init.sls b/consul/init.sls index e9ab7b4..2a74435 100644 --- a/consul/init.sls +++ b/consul/init.sls @@ -91,20 +91,15 @@ consul_config: - require: - user: consul -{% for service in consul.register %} -{% set outer_loop = loop %} -{% for check in service.checks %} -{% if check.script %} -consul_service_register_{{ outer_loop.index }}_{{ loop.index }}: +{% for script in consul.scripts %} +consul_service_register_{{ loop.index }}: file.managed: - - source: {{ check.script }} - - name: /opt/consul/scripts/{{ check.script.split('/')[-1] }} + - source: {{ check.source }} + - name: {{ check.name }} - template: jinja - user: consul - group: consul - mode: 0755 -{% endif %} -{% endfor %} {% endfor %} consul_service_register_config: diff --git a/pillar.example b/pillar.example index 6202750..4be3447 100644 --- a/pillar.example +++ b/pillar.example @@ -14,5 +14,8 @@ consul: register: - name: Redis checks: - - script: salt://files/consul/check_redis.py + - script: /opt/consul/check_redis.py interval: 10s + scripts: + - source: salt://files/consul/check_redis.py + name: /opt/consul/check_redis.py