Last active
January 22, 2021 22:56
-
-
Save rmullinnix/ebb5ef2bb877309aebcd to your computer and use it in GitHub Desktop.
Ansible playbook for consul cluster bounce - ansible-playbook -i hosts.dev cluster_bounce.yml --ask-become-pass (peers.tmpl is in roles/consul/templates; sedfile is in roles/consul/files; main.yml is in roles/consul/vars)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
--- | |
# This Playbook bounces a consul cluster that is unable to elect a leader | |
# push peers.json to the consul/raft data directory, change single quotes to doubles, restart consul servers | |
- hosts: consulservers | |
become: yes | |
# update the peers.json file with the correct consul server ip addresses and port | |
tasks: | |
- include_vars: roles/consul/vars/main.yml | |
- name: Create peers.json file | |
template: src=roles/consul/templates/peers.tmpl dest={{ consul_data_path }}/raft/peers.json owner={{ consul_user }} | |
- name: Copy sedfile | |
copy: src=roles/consul/files/sedfile dest=/tmp/sedfile | |
- name: Correct quotes | |
shell: sed -i -f /tmp/sedfile {{ consul_data_path }}/raft/peers.json | |
- name: restart consul server | |
service: name=consul state=restarted |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
[consulservers] | |
host1.domain.com | |
host2.domain.com | |
host3.domain.com | |
[consulagents] | |
host4.domain.com | |
host5.domain.com |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
--- | |
# roles/consul/vars/main.yml | |
consul_user: consul | |
consul_server_port: 8300 | |
consul_data_path: /usr/local/data/consul |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
[{% for host in groups['consulservers'] %} | |
"{{ hostvars[host]['ansible_eth0']['ipv4']['address'] }}:{{ consul_server_port}}" | |
{% if not loop.last %},{% endif %} | |
{% endfor %}] |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
s/'/\"/g |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment