Add service registry
This commit is contained in:
parent
eb01e9faca
commit
dfd4836983
4 changed files with 52 additions and 0 deletions
|
@ -11,3 +11,4 @@ consul:
|
|||
retry_join: []
|
||||
retry_interval: 30s
|
||||
datacenter: "main"
|
||||
register: []
|
||||
|
|
16
consul/files/services.json
Normal file
16
consul/files/services.json
Normal file
|
@ -0,0 +1,16 @@
|
|||
{% from "consul/map.jinja" import consul with context %}
|
||||
{
|
||||
"services": [
|
||||
{% for service in consul.register.items() %}
|
||||
{
|
||||
{% for key, value in service.items() %}
|
||||
{% if key == 'script' %}
|
||||
"{{ script }}": "/opt/consul/scripts/"{{ value.split('/')[-1] }}{% if not loop.last %},{% endif %}
|
||||
{% else %}
|
||||
"{{ key }}": {{ value | json}}{% if not loop.last %},{% endif %}
|
||||
{% endif %}
|
||||
{% endfor %}
|
||||
}{% if not loop.last %},{% endif %}
|
||||
{% endfor %}
|
||||
]
|
||||
}
|
|
@ -85,6 +85,36 @@ consul_config:
|
|||
- require:
|
||||
- user: consul
|
||||
|
||||
{% for service in consul.se %}
|
||||
{% set outer_loop = loop %}
|
||||
{% for check in service %}
|
||||
{% if check.script %}
|
||||
consul_service_register_{{ outer_loopindex }}_{{ loop.index }}:
|
||||
file.managed:
|
||||
- source: {{ check.script }}
|
||||
- name: /opt/consul/scripts/{{ check.script.split('/')[-1] }}
|
||||
- template: jinja
|
||||
- user: consul
|
||||
- group: consul
|
||||
- mode: 0755
|
||||
{% endif %}
|
||||
{% endfor %}
|
||||
{% endfor %}
|
||||
|
||||
consul_service_register_config:
|
||||
file.managed:
|
||||
- source: salt://consul/files/services.json
|
||||
- name: /etc/consul.d/services.json
|
||||
- template: jinja
|
||||
{% if consul.service != False %}
|
||||
- watch_in:
|
||||
- service: consul
|
||||
{% endif %}
|
||||
- user: consul
|
||||
- group: consul
|
||||
- require:
|
||||
- user: consul
|
||||
|
||||
{% if consul.service != False %}
|
||||
consul_service:
|
||||
service.running:
|
||||
|
|
|
@ -11,3 +11,8 @@ consul:
|
|||
retry_join:
|
||||
- 1.1.1.1
|
||||
- 2.2.2.2
|
||||
register:
|
||||
- name: Redis
|
||||
checks:
|
||||
- script: salt://files/consul/check_redis.py
|
||||
interval: 10s
|
||||
|
|
Loading…
Reference in a new issue