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
include in handler requires full path #71222
Comments
Files identified in the description: If these files are incorrect, please update the |
!component handlers |
I've done a little research here, and I think it is the result of I'm not saying I've decided this is a bug yet, but just adding context for future discussion. https://github.com/ansible/ansible/blob/devel/lib/ansible/playbook/included_file.py#L146-L149 |
dwim should be able to use the subdirs as it falls back to current directory for the file you are in 'handlers/main.yml'. |
This may be sufficient, I haven't tested extensively. If anyone is interested, feel free to test this, and get a PR up: diff --git a/lib/ansible/playbook/included_file.py b/lib/ansible/playbook/included_file.py
index 7870d83a6a..a734a5739c 100644
--- a/lib/ansible/playbook/included_file.py
+++ b/lib/ansible/playbook/included_file.py
@@ -23,6 +23,7 @@ import os
from ansible.errors import AnsibleError
from ansible.module_utils._text import to_text
+from ansible.playbook.handler import Handler
from ansible.playbook.task_include import TaskInclude
from ansible.playbook.role_include import IncludeRole
from ansible.template import Templar
@@ -165,7 +166,12 @@ class IncludedFile:
if include_file is None:
if original_task._role:
include_target = templar.template(include_result['include'])
- include_file = loader.path_dwim_relative(original_task._role._role_path, 'tasks', include_target)
+ include_file = loader.path_dwim_relative(
+ original_task._role._role_path,
+ 'handlers' if isinstance(original_task, Handler) else 'tasks',
+ include_target,
+ is_role=True
+ )
else:
include_file = loader.path_dwim(include_result['include']) I'm not actively working this further right now. |
@nomadcz: Greetings! Thanks for taking the time to open this issue. In order for the community to handle your issue effectively, we need a bit more information. Here are the items we could not find in your description:
Please set the description of this issue with an appropriate template from: |
Files identified in the description: If these files are incorrect, please update the |
SUMMARY
To include tasks for handlers I have to specify full path instead of relative to the role's directory
Similar to: #19609
ISSUE TYPE
COMPONENT NAME
lib/ansible/playbook/included_file.py
ANSIBLE VERSION
CONFIGURATION
OS / ENVIRONMENT
RedHat 7
STEPS TO REPRODUCE
in role's handlers directory I have:
cat main.yml
The full path works ok:
EXPECTED RESULTS
Tasks should be included from path relative to role
ACTUAL RESULTS
Include fails as ansible tries to include handlers-services.yml directly from playbook directory
The text was updated successfully, but these errors were encountered: