DavidWittman / ansible-redis

Highly-configurable Ansible role to install Redis and Redis Sentinel from source

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Error: handler 'restart redis 6379' was not found

alibo opened this issue · comments

Unfortunately, I get this error with Ansible 2.6.2:

TASK [DavidWittman.redis : create redis config file] **************************************************************
ERROR! The requested handler 'restart redis 6379' was not found in either the main handlers list nor in the listening handlers list

Here is the playbook:

---
- name: Configure Redis
  hosts: all
  remote_user: root
  vars:
    - redis_slaveof: 192.168.1.100 6379
    - redis_version: 4.0.10
    - redis_port: 6379
    - redis_maxclients: 10000
    - redis_tcp_backlog: 5000
    - redis_bind: 127.0.0.1
    - redis_save:
      - ""
  roles:
    - redis

It seems Ansible doesn't pass the variable redis_port to the handler, so it can't find the handler restart redis 6379:
https://github.com/DavidWittman/ansible-redis/blob/1.2.5/handlers/main.yml#L2

Is there any workaround for this issue?

I was using this role inside another role with module include_role. I changed redis to DavidWittman.redis and it works. It seems there is an issue with include_role which doesn't pass the variable to the handler or cannot resolve the handler name dynamically.

---
- name: Configure a Redis instance
  tags: redis
  vars:
    - redis_version: "{{ redis_cache_version }}"
    - redis_port: "{{ redis_cache_port }}"
  include_role:
    name: DavidWittman.redis

I close the issue.

It doesn't resolve the handler's name, but it works:

RUNNING HANDLER [DavidWittman.redis : restart redis {{ redis_port }}] *********************************************
changed: [node-1] => {"changed": true, "name": "redis_6379", "state": "started", "status": {"ActiveEnterTimestampMonotonic": "0", "ActiveExitTimestampMonotonic": "0" ...

However if I change the playbook from:

- name: Configure a slave instance of Redis master
  hosts: all
  remote_user: root
  vars:
    - redis_slaveof: "{{ redis_cache_slave_of }}"
    - redis_version: "{{ redis_cache_version }}"
    - redis_port: 6379
  roles:
    - DavidWittman.redis

to:

- name: Configure a slave instance of Redis master
  hosts: all
  remote_user: root
  vars:
    - redis_slaveof: "{{ redis_cache_slave_of }}"
    - redis_version: "{{ redis_cache_version }}"
    - redis_port: "{{ redis_cache_port }}"
  roles:
    - DavidWittman.redis


# group_vars/all
redis_cache_port: 6379
TASK [DavidWittman.redis : create pid directory if it does not exist] *********************************************
skipping: [node-1] => {"changed": false, "skip_reason": "Conditional result was False"}

TASK [DavidWittman.redis : create redis config file] **************************************************************
ERROR! The requested handler 'restart redis 6379' was not found in either the main handlers list nor in the listening handlers list

It won't work anymore. It's completely weird :(

I reopen the issue.

Works for me on Ansible version 2.7.0rc4. It was fixed here ansible/ansible#41837.

With Ansible 2.7.5, I see the same issue as @alibo -- if I use a fixed port number, then the handler is run fine, but if I provide the port number as another variable, the handler is not found.

It seems it will never be allowed. Here's why:
ansible/ansible#48466 (comment)

Task names (including handlers) cannot depend on a host var as they need to be the same for all hosts, it does not matter that you use the 'all' group as that is still flattened and 'per host'.