Skip to content

Commit

Permalink
Add option to detect master/slave status from runtime status
Browse files Browse the repository at this point in the history
  • Loading branch information
danielkza committed Nov 16, 2016
1 parent f0d694b commit 72b5b5a
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 2 deletions.
2 changes: 2 additions & 0 deletions defaults/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,8 @@ redis_socket_perm: 755
## Replication options
# Set slaveof just as you would in redis.conf. (e.g. "redis01 6379")
redis_slaveof: false
# Ignore manually assigned roles for instances if runtime status can be used instead
redis_runtime_replication_role: yes
# Make slaves read-only. "yes" or "no"
redis_slave_read_only: "yes"
redis_slave_priority: 100
Expand Down
6 changes: 6 additions & 0 deletions tasks/local_facts.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
vars:
redis_facts_cli_port: "{{ redis_port }}"
when: not redis_sentinel
register: redis_facts_install_result

- name: create redis sentinel facts
template:
Expand All @@ -27,3 +28,8 @@
redis_facts_cli_port: "{{ redis_sentinel_port }}"
redis_facts_sentinel: yes
when: redis_sentinel
register: redis_sentinel_facts_install_result

- name: refresh facts due to new fact scripts
setup:
when: redis_facts_install_result.changed or redis_sentinel_facts_install_result.changed
8 changes: 6 additions & 2 deletions tasks/main.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,12 @@
---
- include: check_vars.yml

- include: local_facts.yml
when: redis_local_facts|bool

- include: runtime_roles.yml
when: not redis_sentinel and redis_runtime_replication_role

- include: install.yml

- include: server.yml
Expand All @@ -13,5 +19,3 @@
tags:
- config

- include: local_facts.yml
when: redis_local_facts|bool
13 changes: 13 additions & 0 deletions tasks/runtime_roles.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
- name: set redis to slave automatically
set_fact:
redis_slaveof: >-
{{ ansible_local[redis_service_name].master_host }}
{{ ansible_local[redis_service_name].master_port }}
when: >
ansible_local[redis_service_name].role|default() == 'slave'
- name: set redis to master automatically
set_fact:
redis_slaveof: ~
when: >
ansible_local[redis_service_name].role|default() == 'master'

0 comments on commit 72b5b5a

Please sign in to comment.