diff options
author | Martin Krizek <martin.krizek@gmail.com> | 2023-11-22 17:42:51 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-11-22 17:42:51 +0100 |
commit | d664f13b4a117b324f107b603e9b8e2bb9af50c5 (patch) | |
tree | 5ea8230221ea33936fc1942908482a30828c1c4a | |
parent | Update known_hosts module to better handle @cert-authority keys (#70340) (diff) | |
download | ansible-d664f13b4a117b324f107b603e9b8e2bb9af50c5.tar.xz ansible-d664f13b4a117b324f107b603e9b8e2bb9af50c5.zip |
Allow include_tasks handlers for searching role subdirs (#82248)
Fixes #82241
7 files changed, 19 insertions, 2 deletions
diff --git a/changelogs/fragments/82241-handler-include-tasks-from.yml b/changelogs/fragments/82241-handler-include-tasks-from.yml new file mode 100644 index 0000000000..276a612bf7 --- /dev/null +++ b/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) diff --git a/lib/ansible/playbook/included_file.py b/lib/ansible/playbook/included_file.py index 177900f653..14d8982231 100644 --- a/lib/ansible/playbook/included_file.py +++ b/lib/ansible/playbook/included_file.py @@ -147,8 +147,8 @@ class IncludedFile: 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: diff --git a/test/integration/targets/handlers/82241.yml b/test/integration/targets/handlers/82241.yml new file mode 100644 index 0000000000..4a9421fbcd --- /dev/null +++ b/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 diff --git a/test/integration/targets/handlers/roles/role-82241/handlers/main.yml b/test/integration/targets/handlers/roles/role-82241/handlers/main.yml new file mode 100644 index 0000000000..ad59b963e2 --- /dev/null +++ b/test/integration/targets/handlers/roles/role-82241/handlers/main.yml @@ -0,0 +1,2 @@ +- name: handler + include_tasks: included_tasks.yml diff --git a/test/integration/targets/handlers/roles/role-82241/tasks/entry_point.yml b/test/integration/targets/handlers/roles/role-82241/tasks/entry_point.yml new file mode 100644 index 0000000000..50aec1c7b3 --- /dev/null +++ b/test/integration/targets/handlers/roles/role-82241/tasks/entry_point.yml @@ -0,0 +1,2 @@ +- command: echo + notify: handler diff --git a/test/integration/targets/handlers/roles/role-82241/tasks/included_tasks.yml b/test/integration/targets/handlers/roles/role-82241/tasks/included_tasks.yml new file mode 100644 index 0000000000..e3ffeb7e13 --- /dev/null +++ b/test/integration/targets/handlers/roles/role-82241/tasks/included_tasks.yml @@ -0,0 +1,2 @@ +- debug: + msg: included_task_from_tasks_dir diff --git a/test/integration/targets/handlers/runme.sh b/test/integration/targets/handlers/runme.sh index e24dad6028..613fa4a818 100755 --- a/test/integration/targets/handlers/runme.sh +++ b/test/integration/targets/handlers/runme.sh @@ -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" ] |