Allow for searching handler subdir for included task via include_role (#81733) (#81758)

Fixes #81722

(cherry picked from commit 1e7f7875c6)
pull/81828/head
Martin Krizek 1 year ago committed by GitHub
parent 8f621fd6cd
commit 2a29739ee6
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -0,0 +1,2 @@
bugfixes:
- Allow for searching handler subdir for included task via include_role (https://github.com/ansible/ansible/issues/81722)

@ -148,9 +148,12 @@ class IncludedFile:
cumulative_path = parent_include_dir cumulative_path = parent_include_dir
include_target = templar.template(include_result['include']) include_target = templar.template(include_result['include'])
if original_task._role: if original_task._role:
new_basedir = os.path.join(original_task._role._role_path, 'tasks', cumulative_path) dirname = 'handlers' if isinstance(original_task, Handler) else 'tasks'
candidates = [loader.path_dwim_relative(original_task._role._role_path, 'tasks', include_target), new_basedir = os.path.join(original_task._role._role_path, dirname, cumulative_path)
loader.path_dwim_relative(new_basedir, 'tasks', include_target)] candidates = [
loader.path_dwim_relative(original_task._role._role_path, dirname, include_target),
loader.path_dwim_relative(new_basedir, dirname, include_target)
]
for include_file in candidates: for include_file in candidates:
try: try:
# may throw OSError # may throw OSError

@ -192,3 +192,6 @@ ansible-playbook test_listen_role_dedup.yml "$@" 2>&1 | tee out.txt
[ "$(grep out.txt -ce 'a handler from a role')" = "1" ] [ "$(grep out.txt -ce 'a handler from a role')" = "1" ]
ansible localhost -m include_role -a "name=r1-dep_chain-vars" "$@" ansible localhost -m include_role -a "name=r1-dep_chain-vars" "$@"
ansible-playbook test_include_tasks_in_include_role.yml "$@" 2>&1 | tee out.txt
[ "$(grep out.txt -ce 'handler ran')" = "1" ]

@ -0,0 +1,5 @@
- hosts: localhost
gather_facts: false
tasks:
- include_role:
name: include_role_include_tasks_handler
Loading…
Cancel
Save