-
Notifications
You must be signed in to change notification settings - Fork 23.7k
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
Including tasks with first_found
fails to find files within same task directory
#82695
Comments
Files identified in the description: If these files are incorrect, please update the |
Caused by a9919dd |
This worked because the role uses an entrypoint in a subdirectory and the role autodetection logic doesn't handle that at all (meaning as a result, none of the normal role paths were searched). The docs suggest the task's directory is searched regardless https://docs.ansible.com/ansible/latest/playbook_guide/playbook_pathing.html#resolving-local-relative-paths:
but I think the documentation was more accurate for roles before that was added in #73818. Maybe the fix is just to change always append the source's current directory? diff --git a/lib/ansible/parsing/dataloader.py b/lib/ansible/parsing/dataloader.py
index db695ba8dd..da198e05aa 100644
--- a/lib/ansible/parsing/dataloader.py
+++ b/lib/ansible/parsing/dataloader.py
@@ -316,11 +316,10 @@ class DataLoader:
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)) |
Thanks for taking a quick look at the issue. Since I am not sure about the release criteria and time taken to get it packaged in distribution, is there any workaround that I can use in the meanwhile? Our CI workflow heavily uses |
You could try using |
If not obvious, issue is also seen when tasks are included from a different sub directory within the same role as outlined below: ---
# shift.yml
- hosts: localhost
roles:
- shift ---
# roles/shift/tasks/main.yml
- name: Include tasks from current role
include_tasks: within/main.yml ---
# roles/shift/tasks/within/main.yml
- name: Include files
include_tasks: "{{ include_file }}"
with_first_found:
- files:
- one.yml
- two.yml
- three.yml
loop_control:
loop_var: include_file ---
# roles/shift/tasks/within/two.yml
- debug:
msg: "All good" |
Recent update to ansible v2.16.3 broke[1] the promised action of first_found plugin to find files with relative paths when tasks are included from a different subdirectory other than where its main.yml is located. Thus we temporarily switch to use absolute paths wherever required until fix is available with an updated package. [1] ansible/ansible#82695 Signed-off-by: Anoop C S <anoopcs@cryptolab.net>
Recent update to ansible v2.16.3 broke[1] the promised action of first_found plugin to find files with relative paths when tasks are included from a different subdirectory other than where its main.yml is located. Thus we temporarily switch to use absolute paths wherever required until fix is available with an updated package. [1] ansible/ansible#82695 Signed-off-by: Anoop C S <anoopcs@cryptolab.net>
Recent update to ansible v2.16.3 broke[1] the promised action of first_found plugin to find files with relative paths when tasks are included from a different subdirectory other than where its main.yml is located. Thus we temporarily switch to use absolute paths wherever required until fix is available with an updated package. [1] ansible/ansible#82695 Signed-off-by: Anoop C S <anoopcs@cryptolab.net>
Recent update to ansible v2.16.3 broke[1] the promised action of first_found plugin to find files with relative paths when tasks are included from a different subdirectory other than where its main.yml is located. Thus we temporarily switch to use absolute paths wherever required until fix is available with an updated package. [1] ansible/ansible#82695 Signed-off-by: Anoop C S <anoopcs@cryptolab.net>
Summary
Running a playbook, as described further down, which includes tasks from different yaml file within the same task directory using
first_found
causes the following error terminating the execution:Please note that this is a regression from v2.16.2 where the reproducer works as expected.
Issue Type
Bug Report
Component Name
first_found
Ansible Version
Configuration
CONFIG_FILE() = /etc/ansible/ansible.cfg
OS / Environment
CentOS Stream 8
Steps to Reproduce
Expected Results
Actual Results
Code of Conduct
The text was updated successfully, but these errors were encountered: