Skip to content

Commit

Permalink
Fix handlers definitions
Browse files Browse the repository at this point in the history
Fixes DavidWittman#193.

As stated here DavidWittman#193 (comment)
variables in task name cannot rely on host vars.
  • Loading branch information
Jonathan Piron committed Jan 16, 2020
1 parent 98bef17 commit f09bdf6
Show file tree
Hide file tree
Showing 5 changed files with 37 additions and 26 deletions.
6 changes: 5 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

- Ansible 2.1+
- Compatible with most versions of Ubuntu/Debian and RHEL/CentOS 6.x

## Contents

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

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.

### Multiple role inclusions

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)).


## Advanced Options

Expand Down
4 changes: 2 additions & 2 deletions handlers/main.yml
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
---
- name: "restart redis {{ redis_port }}"
- name: "restart redis"
service:
name: "{{ redis_service_name }}"
state: restarted
when: redis_as_service

- name: "restart sentinel {{ redis_sentinel_port }}"
- name: "restart sentinel"
service:
name: sentinel_{{ redis_sentinel_port }}
state: restarted
Expand Down
6 changes: 3 additions & 3 deletions tasks/sentinel.yml
Original file line number Diff line number Diff line change
Expand Up @@ -107,21 +107,21 @@
dest: /etc/redis/sentinel_{{ redis_sentinel_port }}.conf
owner: "{{ redis_user }}"
mode: 0640
notify: "restart sentinel {{ redis_sentinel_port }}"
notify: "restart sentinel"

- name: add sentinel init config file
template:
dest: /etc/sysconfig/sentinel_{{ redis_sentinel_port }}
src: redis.init.conf.j2
when: ansible_os_family == "RedHat"
notify: "restart sentinel {{ redis_sentinel_port }}"
notify: "restart sentinel"

- name: add sentinel init config file
template:
dest: /etc/default/sentinel_{{ redis_sentinel_port }}
src: redis.init.conf.j2
when: ansible_os_family == "Debian"
notify: "restart sentinel {{ redis_sentinel_port }}"
notify: "restart sentinel"

# Flush handlers before ensuring the service is started to prevent
# a start and then restart
Expand Down
6 changes: 3 additions & 3 deletions tasks/server.yml
Original file line number Diff line number Diff line change
Expand Up @@ -107,23 +107,23 @@
dest: /etc/redis/{{ redis_port }}.conf
owner: "{{ redis_user }}"
mode: 0640
notify: "restart redis {{ redis_port }}"
notify: "restart redis"

- name: add redis init config file
template:
dest: /etc/sysconfig/{{ redis_service_name }}
src: redis.init.conf.j2
mode: 0600
when: ansible_os_family == "RedHat"
notify: "restart redis {{ redis_port }}"
notify: "restart redis"

- name: add redis init config file
template:
dest: /etc/default/{{ redis_service_name }}
src: redis.init.conf.j2
mode: 0600
when: ansible_os_family == "Debian"
notify: "restart redis {{ redis_port }}"
notify: "restart redis"

# Flush handlers before ensuring the service is started to prevent
# a start and then restart
Expand Down
41 changes: 24 additions & 17 deletions test/test_all.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,22 +8,29 @@
redis_version: 3.0.7
redis_password: ant1r3z
redis_travis_ci: true
roles:
- role: ../../ansible-redis
redis_port: 7379
tasks:
- import_role: ../../ansible-redis
vars:
redis_port: 7379

- role: ../../ansible-redis
redis_port: 8379
redis_slaveof: 127.0.0.1 7379
redis_local_facts: false
- meta: flush_handlers

- role: ../../ansible-redis
redis_sentinel: true
redis_sentinel_port: 27379
redis_sentinel_monitors:
- name: master01
host: 127.0.0.1
port: 7379
quorum: 1
auth_pass: "{{ redis_password }}"
redis_local_facts: false
- import_role: ../../ansible-redis
vars:
redis_port: 8379
redis_slaveof: 127.0.0.1 7379
redis_local_facts: false

- meta: flush_handlers

- import_role: ../../ansible-redis
vars:
redis_sentinel: true
redis_sentinel_port: 27379
redis_sentinel_monitors:
- name: master01
host: 127.0.0.1
port: 7379
quorum: 1
auth_pass: "{{ redis_password }}"
redis_local_facts: false

0 comments on commit f09bdf6

Please sign in to comment.