Skip to content

Instantly share code, notes, and snippets.

@abn
Created February 15, 2016 02:20
Show Gist options
  • Save abn/526781365832b1ab9785 to your computer and use it in GitHub Desktop.
Save abn/526781365832b1ab9785 to your computer and use it in GitHub Desktop.
Mantl: Reset consul peers to recover from a cluster outage.
---
# https://www.consul.io/docs/guides/outage.html
# do a rolling restart; be nice to the cluster
- hosts: role=control
serial: 1
gather_facts: no
tasks:
- name: set consul maintenance enable
command: consul maint -enable -reason "{{ lookup('env', 'USER') }} reset consul peers"
tags:
- reset
- name: stop consul
become: yes
service: >
name=consul
state=stopped
tags:
- reset
- copy:
dest: /var/lib/consul/raft/peers.json
content: "[{% for host in groups[consul_servers_group] | intersect(groups[consul_dc_group]) %}\"{{ hostvars[host].private_ipv4 }}:8300\"{% if not loop.last %}, {% endif %}{% endfor %}]"
tags:
- configure
- name: start consul
become: yes
service: >
name=consul
state=started
tags:
- reset
- name: wait for consul to listen
wait_for:
port: 8500
tags:
- restart
- name: set consul maintenance disable
command: consul maint -disable
tags:
- restart
@langston-barrett
Copy link

Would you mind making a PR for this? Then we could close mantl/mantl#948

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment