Skip to content

Commit 72b5b5a

Browse files
committed
Add option to detect master/slave status from runtime status
1 parent f0d694b commit 72b5b5a

File tree

4 files changed

+27
-2
lines changed

4 files changed

+27
-2
lines changed

defaults/main.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,8 @@ redis_socket_perm: 755
4141
## Replication options
4242
# Set slaveof just as you would in redis.conf. (e.g. "redis01 6379")
4343
redis_slaveof: false
44+
# Ignore manually assigned roles for instances if runtime status can be used instead
45+
redis_runtime_replication_role: yes
4446
# Make slaves read-only. "yes" or "no"
4547
redis_slave_read_only: "yes"
4648
redis_slave_priority: 100

tasks/local_facts.yml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
vars:
1818
redis_facts_cli_port: "{{ redis_port }}"
1919
when: not redis_sentinel
20+
register: redis_facts_install_result
2021

2122
- name: create redis sentinel facts
2223
template:
@@ -27,3 +28,8 @@
2728
redis_facts_cli_port: "{{ redis_sentinel_port }}"
2829
redis_facts_sentinel: yes
2930
when: redis_sentinel
31+
register: redis_sentinel_facts_install_result
32+
33+
- name: refresh facts due to new fact scripts
34+
setup:
35+
when: redis_facts_install_result.changed or redis_sentinel_facts_install_result.changed

tasks/main.yml

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,12 @@
11
---
22
- include: check_vars.yml
33

4+
- include: local_facts.yml
5+
when: redis_local_facts|bool
6+
7+
- include: runtime_roles.yml
8+
when: not redis_sentinel and redis_runtime_replication_role
9+
410
- include: install.yml
511

612
- include: server.yml
@@ -13,5 +19,3 @@
1319
tags:
1420
- config
1521

16-
- include: local_facts.yml
17-
when: redis_local_facts|bool

tasks/runtime_roles.yml

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
- name: set redis to slave automatically
2+
set_fact:
3+
redis_slaveof: >-
4+
{{ ansible_local[redis_service_name].master_host }}
5+
{{ ansible_local[redis_service_name].master_port }}
6+
when: >
7+
ansible_local[redis_service_name].role|default() == 'slave'
8+
9+
- name: set redis to master automatically
10+
set_fact:
11+
redis_slaveof: ~
12+
when: >
13+
ansible_local[redis_service_name].role|default() == 'master'

0 commit comments

Comments
 (0)