-
Notifications
You must be signed in to change notification settings - Fork 312
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'devel' of github.com:brianshumate/ansible-consul into d…
…evel
- Loading branch information
Showing
5 changed files
with
147 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
|
||
- name: "Configure consul services" | ||
template: | ||
dest: "{{ consul_configd_path }}/service_{{ item.name }}.json" | ||
src: service.json.j2 | ||
owner: "{{ consul_user }}" | ||
group: "{{ consul_group }}" | ||
mode: 0644 | ||
with_items: "{{ consul_services }}" | ||
notify: | ||
- restart consul | ||
|
||
- name: Get the list of service config file | ||
find: | ||
paths: "{{ consul_configd_path }}" | ||
file_type: file | ||
register: services_enabled | ||
|
||
- name: Set fact with list of existing configuration file | ||
set_fact: | ||
list_current_service_config: "{{ list_current_service_config |default([]) + [item.path] }}" | ||
with_items: "{{ services_enabled['files'] }}" | ||
|
||
- name: Set fact with list of service we manage | ||
set_fact: | ||
managed_files: "{{ managed_files |default([]) }} + \ | ||
[ '{{ consul_configd_path }}/service_{{ item['name'] }}.json' ]" | ||
with_items: "{{ consul_services }}" | ||
|
||
- name: Delete non declared services | ||
file: | ||
path: "{{ item }}" | ||
state: absent | ||
when: item not in managed_files | ||
with_items: "{{ list_current_service_config }}" | ||
notify: | ||
- restart consul |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
{ | ||
"service": { | ||
"name": "{{ item.name }}", | ||
{% if item.id is defined -%} | ||
"id": "{{ item.id }}", | ||
{% endif -%} | ||
{% if item.port is defined -%} | ||
"port": {{ item.port }}, | ||
{% endif -%} | ||
{% if item.address is defined -%} | ||
"address": "{{ item.address }}", | ||
{% endif -%} | ||
{% if item.enable_tag_override is defined -%} | ||
"enable_tag_override": {{ item.enable_tag_override }}, | ||
{% endif -%} | ||
{% if item.kind is defined -%} | ||
"kind": "{{ item.kind }}", | ||
{% endif -%} | ||
{% if item.proxy is defined -%} | ||
"proxy": {{ item.proxy | to_json }}, | ||
{% endif -%} | ||
{% if item.meta is defined -%} | ||
"meta": {{ item.meta | to_json }}, | ||
{% endif -%} | ||
{% if item.checks is defined -%} | ||
"checks": {{ item.checks | to_json }}, | ||
{% endif -%} | ||
{% if item.connect is defined -%} | ||
"connect": {{ item.connect | to_json }}, | ||
{% endif -%} | ||
{% if item.weights is defined -%} | ||
"weights": {{ item.weights | to_json }}, | ||
{% endif -%} | ||
"tags": {% if item.tags is defined -%}{{ item.tags|to_json }}{% else %}[]{% endif -%} | ||
} | ||
} |