Add service registry

This commit is contained in:
Bahadır Kandemir 2015-10-10 00:39:53 +03:00
parent eb01e9faca
commit dfd4836983
4 changed files with 52 additions and 0 deletions

View file

@ -11,3 +11,4 @@ consul:
retry_join: [] retry_join: []
retry_interval: 30s retry_interval: 30s
datacenter: "main" datacenter: "main"
register: []

View 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 %}
]
}

View file

@ -85,6 +85,36 @@ consul_config:
- require: - require:
- user: consul - 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 %} {% if consul.service != False %}
consul_service: consul_service:
service.running: service.running:

View file

@ -11,3 +11,8 @@ consul:
retry_join: retry_join:
- 1.1.1.1 - 1.1.1.1
- 2.2.2.2 - 2.2.2.2
register:
- name: Redis
checks:
- script: salt://files/consul/check_redis.py
interval: 10s