redis/tasks/discover_master.yaml

24 lines
756 B
YAML
Raw Normal View History

---
- name: Discover redis with master role
shell: redis-cli --pass {{ redis_requirepass }} info replication | grep 'role:master'
register: redis_master
changed_when: False
failed_when: False
- name: Set fact about redis master
set_fact:
redis_master_ip: "{{ hostvars[inventory_hostname].ansible_default_ipv4.address | default(hostvars[play_hosts[0]].ansible_default_ipv4.address) }}"
delegate_to: "{{ item }}"
delegate_facts: true
loop: "{{ play_hosts }}"
when: redis_master.rc == 0
- name: Set fact about redis master
set_fact:
redis_master_ip: "{{ hostvars[play_hosts[0]].ansible_default_ipv4.address }}"
when: redis_master_ip is not defined
- debug:
msg: "Master redis IP is {{ redis_master_ip }}"
verbosity: 2