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

Allow include_tasks handlers for searching role subdirs #82248

Merged
merged 1 commit into from Nov 22, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 2 additions & 0 deletions changelogs/fragments/82241-handler-include-tasks-from.yml
@@ -0,0 +1,2 @@
bugfixes:
- Fix issue where an ``include_tasks`` handler in a role was not able to locate a file in ``tasks/`` when ``tasks_from`` was used as a role entry point and ``main.yml`` was not present (https://github.com/ansible/ansible/issues/82241)
4 changes: 2 additions & 2 deletions lib/ansible/playbook/included_file.py
Expand Up @@ -147,8 +147,8 @@ def process_include_results(results, iterator, loader, variable_manager):
dirname = 'handlers' if isinstance(original_task, Handler) else 'tasks'
new_basedir = os.path.join(original_task._role._role_path, dirname, cumulative_path)
candidates = [
loader.path_dwim_relative(original_task._role._role_path, dirname, include_target),
loader.path_dwim_relative(new_basedir, dirname, include_target)
loader.path_dwim_relative(original_task._role._role_path, dirname, include_target, is_role=True),
loader.path_dwim_relative(new_basedir, dirname, include_target, is_role=True)
]
for include_file in candidates:
try:
Expand Down
6 changes: 6 additions & 0 deletions test/integration/targets/handlers/82241.yml
@@ -0,0 +1,6 @@
- hosts: A
gather_facts: false
tasks:
- import_role:
name: role-82241
tasks_from: entry_point.yml
@@ -0,0 +1,2 @@
- name: handler
include_tasks: included_tasks.yml
@@ -0,0 +1,2 @@
- command: echo
notify: handler
@@ -0,0 +1,2 @@
- debug:
msg: included_task_from_tasks_dir
3 changes: 3 additions & 0 deletions test/integration/targets/handlers/runme.sh
Expand Up @@ -210,3 +210,6 @@ ansible-playbook force_handlers_blocks_81533-2.yml -i inventory.handlers "$@" 2>
ansible-playbook nested_flush_handlers_failure_force.yml -i inventory.handlers "$@" 2>&1 | tee out.txt
[ "$(grep out.txt -ce 'flush_handlers_rescued')" = "1" ]
[ "$(grep out.txt -ce 'flush_handlers_always')" = "2" ]

ansible-playbook 82241.yml -i inventory.handlers "$@" 2>&1 | tee out.txt
[ "$(grep out.txt -ce 'included_task_from_tasks_dir')" = "1" ]