DavidWittman / ansible-redis

Highly-configurable Ansible role to install Redis and Redis Sentinel from source
MIT License
663 stars 288 forks source link

Error: handler 'restart redis 6379' was not found #193

Closed alibo closed 4 years ago

alibo commented 6 years ago

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?

alibo commented 6 years ago

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.

alibo commented 6 years ago

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.

petrprikryl commented 6 years ago

Works for me on Ansible version 2.7.0rc4. It was fixed here https://github.com/ansible/ansible/pull/41837.

Genocidicbunny commented 5 years ago

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.

tamer-hassan commented 5 years ago

It seems it will never be allowed. Here's why: https://github.com/ansible/ansible/issues/48466#issuecomment-437985126

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