lookups, make file searching use better is_role (#82290)

* lookups, make file searching use better is_role

 The dwim function will internally try by detecting tasks/main['','.yml','.yaml]
 but this is far from optimial, the existince of role path in vars is much better
 indicator that we can use to pass a hint


* updated test to avoid main.yml
pull/82392/head
Brian Coca 5 months ago committed by GitHub
parent 5573d4cde9
commit a9919dd7f6
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -0,0 +1,2 @@
bugfixes:
- dwim functions for lookups should be better at detectging role context even in abscense of tasks/main.

@ -115,7 +115,7 @@ class LookupBase(AnsiblePlugin):
result = None
try:
result = self._loader.path_dwim_relative_stack(paths, subdir, needle)
result = self._loader.path_dwim_relative_stack(paths, subdir, needle, is_role=bool('role_path' in myvars))
except AnsibleFileNotFound:
if not ignore_missing:
self._display.warning("Unable to find '%s' in expected paths (use -vvvvv to see paths)" % needle)

@ -4,9 +4,11 @@
pre_tasks:
- name: remove {{ remove }}
file: path={{ playbook_dir }}/{{ remove }} state=absent
roles:
- showfile
post_tasks:
tasks:
- import_role:
name: showfile
tasks_from: notmain.yml
- name: from play
set_fact: play_result="{{lookup('file', 'testfile')}}"

Loading…
Cancel
Save