2022-09-16 23:46:37 +00:00
|
|
|
---
|
|
|
|
- name: Recovery Consul
|
|
|
|
hosts: consul_instances
|
|
|
|
|
|
|
|
tasks:
|
2022-09-28 04:29:00 +00:00
|
|
|
- name: Stop Consul
|
2022-09-16 23:46:37 +00:00
|
|
|
systemd:
|
|
|
|
name: consul
|
|
|
|
state: stopped
|
|
|
|
become: true
|
|
|
|
|
|
|
|
- name: Get node-id
|
|
|
|
slurp:
|
|
|
|
src: /opt/consul/node-id
|
|
|
|
register: consul_node_id
|
|
|
|
become: true
|
|
|
|
|
|
|
|
- name: Node Id
|
|
|
|
debug:
|
|
|
|
msg: "node_id: {{ consul_node_id.content }}"
|
|
|
|
|
|
|
|
- name: Address
|
|
|
|
debug:
|
|
|
|
msg: "address: {{ ansible_default_ipv4.address }}"
|
|
|
|
|
|
|
|
- name: Save
|
|
|
|
copy:
|
|
|
|
dest: "/opt/consul/raft/peers.json"
|
|
|
|
content: |
|
|
|
|
[
|
|
|
|
{% for host in ansible_play_hosts|reject('equalto', inventory_hostname) -%}
|
|
|
|
{
|
|
|
|
"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
|