Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions ansible/consul-services.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
---
- hosts: rabbitmq
- hosts: redis

- hosts: vault
roles:
- { role: consul-services }
2 changes: 1 addition & 1 deletion ansible/group_vars/all.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
---
# registry settings
registry_env: "prod"
registry_port: 80

# for docker stop old container
stop_time: 5
Expand Down Expand Up @@ -102,4 +103,3 @@ shiva_port: 3000

# swarm
swarm_master_port: 2375

37 changes: 37 additions & 0 deletions ansible/roles/consul-services/tasks/main.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
---
- name: make /etc/consul.d folder
sudo: yes
file:
path=/etc/consul.d
state=directory

- name: remove all current configs
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why do we need to do this? the template below should update the configs, if you do this then you always update the files.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

if you remove a service; it's really annoying to add a 'soft-delete' to each of the items below that you want to remove, so I'm figuring just clean it out every time (also prevents me from adding something manually hehe)

sudo: yes
shell: rm -f /etc/consul.d/*.json

- name: put service files in place
sudo: yes
template:
dest=/etc/consul.d/{{ item.name }}.json
src=service.json
with_items:
- name: 'datadog'
host_address: '{{ datadog_host_address }}'
tags: ['master']
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

if tags are not dynamic why not just set them in the template?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

they could be. I don't want to tie down the template up front. you could just leave these out, I believe...

port: '{{ datadog_port }}'
- name: 'rabbitmq'
host_address: '{{ rabbit_host_address }}'
tags: ['master']
port: '{{ rabbit_port }}'
- name: 'redis'
host_address: '{{ redis_host_address }}'
tags: ['master']
port: '{{ redis_port }}'
- name: 'registry'
host_address: '{{ registry_host }}'
tags: ['master']
port: '{{ registry_port }}'

- name: send consul SIGUP to reload services
sudo: yes
shell: pkill --signal SIGHUP consul
8 changes: 8 additions & 0 deletions ansible/roles/consul-services/templates/service.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
"service": {
"name": "{{ item.name }}",
"tags": [ "{{ item.tags | join('","') }}" ],
"address": "{{ item.host_address }}",
"port": {{ item.port }}
}
}