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

Handler not found in included role when using variable in name and variable is defined in inventory or host_vars #48466

Closed
Pitmairen opened this issue Nov 10, 2018 · 4 comments
Labels
affects_2.7 This issue/PR affects Ansible v2.7 bug This issue/PR relates to a bug. python3 support:core This issue/PR relates to code supported by the Ansible Engineering Team.

Comments

@Pitmairen
Copy link

SUMMARY

If a role is included and it defines a handler that is using a variable in the handler's name, the handler is not found in some situations, it depends on where the variable is defined.

ISSUE TYPE
  • Bug Report
COMPONENT NAME

handlers

ANSIBLE VERSION
ansible 2.7.1
  config file = /etc/ansible/ansible.cfg
  configured module search path = ['/home/abc/.ansible/plugins/modules', '/usr/share/ansible/plugins/modules']
  ansible python module location = /usr/lib/python3.7/site-packages/ansible
  executable location = /usr/bin/ansible
  python version = 3.7.1 (default, Oct 22 2018, 10:41:28) [GCC 8.2.1 20180831]
ansible 2.8.0.dev0 (devel fccbbf3405) last updated 2018/11/10 08:41:20 (GMT +200)
  config file = /etc/ansible/ansible.cfg
  configured module search path = ['/home/abc/.ansible/plugins/modules', '/usr/share/ansible/plugins/modules']
  ansible python module location = /home/abc/handler-bug/ansible/lib/ansible
  executable location = /home/abc/handler-bug/ansible/bin/ansible
  python version = 3.7.1 (default, Oct 22 2018, 10:41:28) [GCC 8.2.1 20180831]
CONFIGURATION
OS / ENVIRONMENT

Control machine Arch linux
Targets: all

STEPS TO REPRODUCE

Run the bug.yml playbook from this repository: https://github.com/Pitmairen/ansbile-handlers-bug

If the variables are defined in the hosts file or the host_vars file (service3 in example) the play crashes with the error: ERROR! The requested handler '...' was not found:

ansible-playbook -i hosts bug.yml

If the variables are defined in the playbook file or on the command line it works fine.

ansible-playbook -i hosts bug.yml --extra-vars service3_name=service3
EXPECTED RESULTS

All handlers are found

ACTUAL RESULTS
PLAY [Ansible handler bug] *****************************************************************************************

TASK [Gathering Facts] *********************************************************************************************
ok: [localhost]

TASK [include_role : role1] ****************************************************************************************

TASK [role1 : Test service1] ***************************************************************************************
changed: [localhost]

TASK [include_role : role1] ****************************************************************************************

TASK [role1 : Test service2] ***************************************************************************************
changed: [localhost]

TASK [include_role : role1] ****************************************************************************************

TASK [role1 : Test service3] ***************************************************************************************
ERROR! The requested handler 'restart service3' was not found in either the main handlers list nor in the listeninghandlers list
@ansibot
Copy link
Contributor

ansibot commented Nov 10, 2018

Hi @Pitmairen, thank you for submitting this issue!

click here for bot help

@ansibot
Copy link
Contributor

ansibot commented Nov 10, 2018

Files identified in the description:

If these files are inaccurate, please update the component name section of the description or use the !component bot command.

click here for bot help

@ansibot ansibot added affects_2.7 This issue/PR affects Ansible v2.7 bug This issue/PR relates to a bug. needs_triage Needs a first human triage before being processed. python3 support:core This issue/PR relates to code supported by the Ansible Engineering Team. labels Nov 10, 2018
@astik
Copy link

astik commented Nov 11, 2018

Argh, i've been working also on this bug and have taken too much time to submit it (i have marked my bug report as a duplicate of yours).
My analysis leads to the same conclusion.
I also have created a project with demo that show the problem : https://github.com/astik/ansible-role-variable-and-multi-instanciation.

@bcoca bcoca removed the needs_triage Needs a first human triage before being processed. label Nov 12, 2018
@bcoca
Copy link
Member

bcoca commented Nov 12, 2018

Possible Misunderstanding

Hi!

Thanks very much for your submission to Ansible. It sincerely means a lot to us.

We believe the ticket you have filed is being somewhat misunderstood, as one thing works a little differently than stated.

In the future, this might be a topic more well suited for the user list, which you can also post here if you'd like some more help with the above.

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

Thank you once again for this and your interest in Ansible!

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
affects_2.7 This issue/PR affects Ansible v2.7 bug This issue/PR relates to a bug. python3 support:core This issue/PR relates to code supported by the Ansible Engineering Team.
Projects
None yet
Development

No branches or pull requests

4 participants