registering node services in consul

This commit is contained in:
Jonathan Math 2021-02-15 19:16:08 -05:00
parent 61c8e70735
commit 710fedcf23
4 changed files with 39 additions and 1 deletions

View file

@ -0,0 +1,9 @@
---
# File: main.yml - Handlers for Consul
- name: reload consul configuration
become: yes
service:
name: consul
state: reloaded
listen: reload consul

View file

@ -32,3 +32,23 @@
command: 'node favicons.js'
target_host: 'node-favicons'
when: "'{{item.target_host}}' in ansible_hostname"
- name: Register nodes in consul
become: yes
template:
src: consul_service.json
dest: /etc/consul.d/{{item.target_host}}.json
with_items:
- port: 8888
target_host: 'node-socket'
- port: 3060
target_host: 'node-page'
- port: 4040
target_host: 'node-text'
- port: 3030
target_host: 'node-favicons'
notify:
- reload consul
when: "'{{item.target_host}}' in ansible_hostname"

View file

@ -0,0 +1,9 @@
{
"service": {
"name": "{{ item.target_host }}",
"tags": [
"node"
],
"port": {{ item.port }}
}
}

View file

@ -15,5 +15,5 @@
- repo
- {role: 'consul', tags: 'consul'}
- {role: 'consul-client', tags: 'consul'}
- node
- {role: 'node', tags: 'node'}