Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
alibo opened this issue Jul 31, 2018 · 5 comments · Fixed by #231
Closed

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

alibo opened this issue Jul 31, 2018 · 5 comments · Fixed by #231

Comments

@alibo
Copy link

alibo commented Jul 31, 2018

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
Copy link
Author

alibo commented Aug 1, 2018

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 alibo closed this as completed Aug 1, 2018
@alibo
Copy link
Author

alibo commented Aug 1, 2018

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.

@alibo alibo reopened this Aug 1, 2018
@petrprikryl
Copy link

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

@Genocidicbunny
Copy link

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
Copy link

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

jpiron pushed a commit to jpiron/ansible-redis that referenced this issue Jan 16, 2020
Fixes DavidWittman#193.

As stated here DavidWittman#193 (comment)
variables in task name cannot rely on host vars.
jpiron pushed a commit to jpiron/ansible-redis that referenced this issue Jan 16, 2020
Fixes DavidWittman#193.

As stated here DavidWittman#193 (comment)
variables in task name cannot rely on host vars.
jpiron pushed a commit to jpiron/ansible-redis that referenced this issue Jan 16, 2020
Fixes DavidWittman#193.

As stated here DavidWittman#193 (comment)
variables in task name cannot rely on host vars.
DavidWittman pushed a commit that referenced this issue Jan 23, 2020
* Fix handlers definitions

Fixes #193.

As stated here #193 (comment)
variables in task name cannot rely on host vars.

* Drop support for Ansible versions before 2.4
rndmh3ro pushed a commit to telekom-mms/ansible-redis that referenced this issue Nov 27, 2020
* Fix handlers definitions

Fixes DavidWittman#193.

As stated here DavidWittman#193 (comment)
variables in task name cannot rely on host vars.

* Drop support for Ansible versions before 2.4
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants