homelab-nomad/ansible_playbooks/recover-consul.yaml

89 lines
1.8 KiB
YAML
Raw Normal View History

---
- name: Stop Nomad
hosts: nomad_instances
tasks:
- name: Stop Nomad
systemd:
name: nomad
state: stopped
become: true
- name: Stop Vault
hosts: vault_instances
2023-03-17 18:46:20 +00:00
gather_facts: false
tasks:
- name: Stop Vault
systemd:
name: vault
state: stopped
become: true
2022-11-15 07:10:16 +00:00
- name: Recover Consul
hosts: consul_instances
2023-03-17 18:46:20 +00:00
gather_facts: false
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 | b64decode }}
2022-11-10 18:15:30 +00:00
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 | b64decode }}",
"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
- name: Start Vault
hosts: vault_instances
2023-03-17 18:46:20 +00:00
gather_facts: false
tasks:
- name: Start Vault
systemd:
name: vault
state: started
become: true
- name: Start Nomad
hosts: nomad_instances
2023-03-17 18:46:20 +00:00
gather_facts: false
tasks:
- name: Start Nomad
systemd:
name: nomad
state: started
become: true