Simpler configuration for services
This commit is contained in:
parent
54f5ce0389
commit
fe712f5f41
3 changed files with 11 additions and 31 deletions
|
@ -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 %}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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:
|
||||
|
|
|
@ -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
|
||||
|
|
Loading…
Reference in a new issue