Skip to content
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

Fix fileglob plugin with non-existent subdirectory #69452

Merged
merged 1 commit into from May 12, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
@@ -0,0 +1,4 @@
bugfixes:
- Fix an issue with the ``fileglob`` plugin where passing a subdirectory of
non-existent directory would cause it to fail -
https://github.com/ansible/ansible/issues/69450
9 changes: 5 additions & 4 deletions lib/ansible/plugins/lookup/fileglob.py
Expand Up @@ -72,8 +72,9 @@ def run(self, terms, variables=None, **kwargs):
found_paths.append(p)

for dwimmed_path in found_paths:
globbed = glob.glob(to_bytes(os.path.join(dwimmed_path, term_file), errors='surrogate_or_strict'))
ret.extend(to_text(g, errors='surrogate_or_strict') for g in globbed if os.path.isfile(g))
if ret:
break
if dwimmed_path:
globbed = glob.glob(to_bytes(os.path.join(dwimmed_path, term_file), errors='surrogate_or_strict'))
ret.extend(to_text(g, errors='surrogate_or_strict') for g in globbed if os.path.isfile(g))
if ret:
break
return ret
6 changes: 6 additions & 0 deletions test/integration/targets/fileglob/non_existent/play.yml
@@ -0,0 +1,6 @@
- hosts: localhost
gather_facts: false
tasks:
- name: fileglob should be empty
assert:
that: q("fileglob", seed) | length == 0
6 changes: 6 additions & 0 deletions test/integration/targets/fileglob/runme.sh
Expand Up @@ -7,3 +7,9 @@ for seed in play_adj play_adj_subdir somepath/play_adj_subsubdir in_role otherpa
do
ansible-playbook find_levels/play.yml -e "seed='${seed}'" "$@"
done

# non-existent paths
for seed in foo foo/bar foo/bar/baz
do
ansible-playbook non_existent/play.yml -e "seed='${seed}'" "$@"
done