Simpler configuration for services

This commit is contained in:
Bahadır Kandemir 2015-10-10 01:13:15 +03:00
parent 54f5ce0389
commit fe712f5f41
3 changed files with 11 additions and 31 deletions

View file

@ -1,24 +1,6 @@
{% from "consul/map.jinja" import consul with context %} {% from "consul/map.jinja" import consul with context %}
{ {
"services": [ "services": {
{% for service in consul.register %} {% consul.register | json %}
{ }
{% 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 %}
]
} }

View file

@ -91,20 +91,15 @@ consul_config:
- require: - require:
- user: consul - user: consul
{% for service in consul.register %} {% for script in consul.scripts %}
{% set outer_loop = loop %} consul_service_register_{{ loop.index }}:
{% for check in service.checks %}
{% if check.script %}
consul_service_register_{{ outer_loop.index }}_{{ loop.index }}:
file.managed: file.managed:
- source: {{ check.script }} - source: {{ check.source }}
- name: /opt/consul/scripts/{{ check.script.split('/')[-1] }} - name: {{ check.name }}
- template: jinja - template: jinja
- user: consul - user: consul
- group: consul - group: consul
- mode: 0755 - mode: 0755
{% endif %}
{% endfor %}
{% endfor %} {% endfor %}
consul_service_register_config: consul_service_register_config:

View file

@ -14,5 +14,8 @@ consul:
register: register:
- name: Redis - name: Redis
checks: checks:
- script: salt://files/consul/check_redis.py - script: /opt/consul/check_redis.py
interval: 10s interval: 10s
scripts:
- source: salt://files/consul/check_redis.py
name: /opt/consul/check_redis.py