homelab-nomad/ansible_playbooks/recover-consul.yaml

45 lines
1.1 KiB
YAML
Raw Normal View History

---
2022-11-15 07:10:16 +00:00
- name: Recover Consul
hosts: consul_instances
tasks:
2022-09-28 04:29:00 +00:00
- name: Stop Consul
systemd:
name: consul
state: stopped
become: true
- name: Get node-id
slurp:
src: /opt/consul/node-id
register: consul_node_id
become: true
2022-11-10 18:15:30 +00:00
- name: Node Info
debug:
2022-11-10 18:15:30 +00:00
msg: |
node_id: {{ consul_node_id.content }}
address: {{ ansible_default_ipv4.address }}
- name: Save
copy:
dest: "/opt/consul/raft/peers.json"
2022-11-10 18:15:30 +00:00
# I used to have reject('equalto', inventory_hostname) in the loop, but I'm not sure if I should
content: |
[
2022-11-10 18:15:30 +00:00
{% for host in ansible_play_hosts -%}
{
"id": "{{ hostvars[host].consul_node_id.content }}",
"address": "{{ hostvars[host].ansible_default_ipv4.address }}:8300",
"non_voter": false
}{% if not loop.last %},{% endif %}
{% endfor -%}
]
become: true
- name: Restart Consul
systemd:
name: consul
state: restarted
become: true