Skip to content

Commit 4d59b91

Browse files
author
Jonathan Piron
committed
Fix handlers definitions
Fixes #193. As stated here #193 (comment) variables in task name cannot rely on host vars.
1 parent 98bef17 commit 4d59b91

File tree

5 files changed

+40
-26
lines changed

5 files changed

+40
-26
lines changed

README.md

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44

55
- Ansible 2.1+
66
- Compatible with most versions of Ubuntu/Debian and RHEL/CentOS 6.x
7-
7+
88
## Contents
99

1010
1. [Installation](#installation)
@@ -145,6 +145,10 @@ This will configure the Sentinel nodes to monitor the master we created above us
145145

146146
Along with the variables listed above, Sentinel has a number of its own configurables just as Redis server does. These are prefixed with `redis_sentinel_`, and are enumerated in the **Role Variables** section below.
147147

148+
### Multiple role inclusions
149+
150+
Should you need to execute the role several times, have a look at `test/test_all.yml` to see how to proceed. See [here](https://github.com/DavidWittman/ansible-redis/issues/133) and [here](https://github.com/DavidWittman/ansible-redis/issues/193) for context.
151+
148152

149153
## Advanced Options
150154

handlers/main.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
---
2-
- name: "restart redis {{ redis_port }}"
2+
- name: "restart redis"
33
service:
44
name: "{{ redis_service_name }}"
55
state: restarted
66
when: redis_as_service
77

8-
- name: "restart sentinel {{ redis_sentinel_port }}"
8+
- name: "restart sentinel"
99
service:
1010
name: sentinel_{{ redis_sentinel_port }}
1111
state: restarted

tasks/sentinel.yml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -107,21 +107,21 @@
107107
dest: /etc/redis/sentinel_{{ redis_sentinel_port }}.conf
108108
owner: "{{ redis_user }}"
109109
mode: 0640
110-
notify: "restart sentinel {{ redis_sentinel_port }}"
110+
notify: "restart sentinel"
111111

112112
- name: add sentinel init config file
113113
template:
114114
dest: /etc/sysconfig/sentinel_{{ redis_sentinel_port }}
115115
src: redis.init.conf.j2
116116
when: ansible_os_family == "RedHat"
117-
notify: "restart sentinel {{ redis_sentinel_port }}"
117+
notify: "restart sentinel"
118118

119119
- name: add sentinel init config file
120120
template:
121121
dest: /etc/default/sentinel_{{ redis_sentinel_port }}
122122
src: redis.init.conf.j2
123123
when: ansible_os_family == "Debian"
124-
notify: "restart sentinel {{ redis_sentinel_port }}"
124+
notify: "restart sentinel"
125125

126126
# Flush handlers before ensuring the service is started to prevent
127127
# a start and then restart

tasks/server.yml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -107,23 +107,23 @@
107107
dest: /etc/redis/{{ redis_port }}.conf
108108
owner: "{{ redis_user }}"
109109
mode: 0640
110-
notify: "restart redis {{ redis_port }}"
110+
notify: "restart redis"
111111

112112
- name: add redis init config file
113113
template:
114114
dest: /etc/sysconfig/{{ redis_service_name }}
115115
src: redis.init.conf.j2
116116
mode: 0600
117117
when: ansible_os_family == "RedHat"
118-
notify: "restart redis {{ redis_port }}"
118+
notify: "restart redis"
119119

120120
- name: add redis init config file
121121
template:
122122
dest: /etc/default/{{ redis_service_name }}
123123
src: redis.init.conf.j2
124124
mode: 0600
125125
when: ansible_os_family == "Debian"
126-
notify: "restart redis {{ redis_port }}"
126+
notify: "restart redis"
127127

128128
# Flush handlers before ensuring the service is started to prevent
129129
# a start and then restart

test/test_all.yml

Lines changed: 27 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -8,22 +8,32 @@
88
redis_version: 3.0.7
99
redis_password: ant1r3z
1010
redis_travis_ci: true
11-
roles:
12-
- role: ../../ansible-redis
13-
redis_port: 7379
11+
tasks:
12+
- import_role:
13+
name: ../../ansible-redis
14+
vars:
15+
redis_port: 7379
1416

15-
- role: ../../ansible-redis
16-
redis_port: 8379
17-
redis_slaveof: 127.0.0.1 7379
18-
redis_local_facts: false
17+
- meta: flush_handlers
1918

20-
- role: ../../ansible-redis
21-
redis_sentinel: true
22-
redis_sentinel_port: 27379
23-
redis_sentinel_monitors:
24-
- name: master01
25-
host: 127.0.0.1
26-
port: 7379
27-
quorum: 1
28-
auth_pass: "{{ redis_password }}"
29-
redis_local_facts: false
19+
- import_role:
20+
name: ../../ansible-redis
21+
vars:
22+
redis_port: 8379
23+
redis_slaveof: 127.0.0.1 7379
24+
redis_local_facts: false
25+
26+
- meta: flush_handlers
27+
28+
- import_role:
29+
name: ../../ansible-redis
30+
vars:
31+
redis_sentinel: true
32+
redis_sentinel_port: 27379
33+
redis_sentinel_monitors:
34+
- name: master01
35+
host: 127.0.0.1
36+
port: 7379
37+
quorum: 1
38+
auth_pass: "{{ redis_password }}"
39+
redis_local_facts: false

0 commit comments

Comments
 (0)