Skip to content

Commit

Permalink
Merge pull request #156 from ernestas-poskus/features/add_consul_serv…
Browse files Browse the repository at this point in the history
…ices_support

Add consul services support
  • Loading branch information
mattfinlayson authored Aug 18, 2016
2 parents a2e36e7 + 143f835 commit 4fd976c
Show file tree
Hide file tree
Showing 5 changed files with 36 additions and 6 deletions.
16 changes: 16 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -308,6 +308,22 @@ Logs will be handled by runit and ```consul_log_file``` set to ```/dev/null``` j
- ansible-consul
```

## Example to register consul services

```yml
consul_services:
- service:
name: "redis localhost"
tags:
- "redis"
address: "127.0.0.1"
port: 6379
checks:
- name: "Redis health check"
tcp: "localhost:6379"
interval: "10s"
timeout: "1s"
```

## Testing

Expand Down
4 changes: 4 additions & 0 deletions defaults/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -118,3 +118,7 @@ consul_cors_support: false
# keep undefined for default behavior (will depend on agent/server role starting with consul 0.7)
# consul_skip_leave_on_interrupt: false
consul_disable_update_check: false

# Define Consul services to add to /etc/consul.d/*
consul_services: {}
consul_services_mode: 0640
7 changes: 6 additions & 1 deletion tasks/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,9 @@
- { include: install-cli.yml, when: consul_install_consul_cli == true }
- { include: dnsmasq.yml, when: consul_install_dnsmasq == true }
- { include: consulate.yml, when: consul_install_consulate == true }
- include: service.yml
- service: >
name=consul
state="{{ consul_service_state }}"
enabled=yes
when: consul_manage_service
- { include: services.yml, when: consul_services is defined and consul_services|length > 0 }
5 changes: 0 additions & 5 deletions tasks/service.yml

This file was deleted.

10 changes: 10 additions & 0 deletions tasks/services.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
---
- name: 'Installing consul services to {{ consul_config_dir }}'
copy:
dest: '{{ consul_config_dir }}/{{ item.service.name.split() | join("_") }}_{{ item.service.port }}.json'
owner: '{{ consul_user }}'
group: '{{ consul_group }}'
mode: '{{ consul_services_mode }}'
content: '{{ item | to_json }}'
with_items: '{{ consul_services }}'
notify: restart consul

0 comments on commit 4fd976c

Please sign in to comment.