Closed alibo closed 4 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.
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 https://github.com/ansible/ansible/pull/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: 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'.
Unfortunately, I get this error with Ansible 2.6.2:
Here is the playbook:
It seems Ansible doesn't pass the variable
redis_port
to the handler, so it can't find the handlerrestart redis 6379
: https://github.com/DavidWittman/ansible-redis/blob/1.2.5/handlers/main.yml#L2Is there any workaround for this issue?