Skip to content

Commit

Permalink
Fix task-adjacent search path in roles (ansible#83621)
Browse files Browse the repository at this point in the history
* Restore search path in the current task file’s directory for roles

(cherry picked from commit 0be66ed)
  • Loading branch information
s-hertel committed Aug 6, 2024
1 parent d550c55 commit 14448f8
Show file tree
Hide file tree
Showing 6 changed files with 18 additions and 5 deletions.
2 changes: 2 additions & 0 deletions changelogs/fragments/dwim_is_role_fix_task_relative.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
bugfixes:
- Fix using the current task's directory for looking up relative paths within roles (https://github.com/ansible/ansible/issues/82695).
9 changes: 4 additions & 5 deletions lib/ansible/parsing/dataloader.py
Original file line number Diff line number Diff line change
Expand Up @@ -318,11 +318,10 @@ def path_dwim_relative_stack(self, paths: list[str], dirname: str, source: str,
if (is_role or self._is_role(path)) and b_pb_base_dir.endswith(b'/tasks'):
search.append(os.path.join(os.path.dirname(b_pb_base_dir), b_dirname, b_source))
search.append(os.path.join(b_pb_base_dir, b_source))
else:
# don't add dirname if user already is using it in source
if b_source.split(b'/')[0] != dirname:
search.append(os.path.join(b_upath, b_dirname, b_source))
search.append(os.path.join(b_upath, b_source))
# don't add dirname if user already is using it in source
if b_source.split(b'/')[0] != dirname:
search.append(os.path.join(b_upath, b_dirname, b_source))
search.append(os.path.join(b_upath, b_source))

# always append basedir as last resort
# don't add dirname if user already is using it in source
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
- include_tasks: subdir/main.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
- assert:
that:
- "lookup('first_found', task_adjacent) is is_file"
vars:
task_adjacent:
- files:
- relative
Empty file.
4 changes: 4 additions & 0 deletions test/integration/targets/lookup_first_found/tasks/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -147,3 +147,7 @@
- ishouldnotbefound.yml
paths:
- "{{role_path}}/vars"

- name: Test relative paths in roles
include_role:
role: "{{ role_path }}/roles/a"

0 comments on commit 14448f8

Please sign in to comment.