From e3ad6c4ff0ff2fba979638dd28bd514aced17f21 Mon Sep 17 00:00:00 2001 From: Ian Fijolek Date: Fri, 16 Sep 2022 16:46:37 -0700 Subject: [PATCH] Add playbook to recover consul using peers --- nomad/recover-consul.yaml | 45 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 45 insertions(+) create mode 100644 nomad/recover-consul.yaml diff --git a/nomad/recover-consul.yaml b/nomad/recover-consul.yaml new file mode 100644 index 0000000..86be259 --- /dev/null +++ b/nomad/recover-consul.yaml @@ -0,0 +1,45 @@ +--- +- name: Recovery Consul + hosts: consul_instances + + tasks: + - name: Restart Consul + 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