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

"file_found" lookup plugin, based on "first_found". Returns list of files found #43692

Open
wants to merge 1 commit into
base: devel
from

Conversation

Projects
None yet
5 participants
@pmonsimi

pmonsimi commented Aug 5, 2018

SUMMARY

Allows to iterate through existing files, instead of having to do a "stat" task registering the result, and iterating over the files founds. It is faster and more readable.

COMPONENT NAME

file_found lookup plugin

Pierre Monsimier
Adding "file_found" lookup plugin, allowing to iterate through files …
…that exist, no more requiring to execute a "stat" task, registering the result and iterating through the registered result
@pmonsimi

This comment has been minimized.

pmonsimi commented on 772d50f Aug 5, 2018

I based this lookup plugin on "first_found", while refactoring it to make it more readable and not iterating twice over the list of params.
There is some questions I don't have answers to :
1 - Why did the first_found plugin use templating ?
try: fn = self._templar.template(fn) except (AnsibleUndefinedVariable, UndefinedError): continue
I didn't use it on the file_found plugin.

2- I am not familiar enough with the inner working of ansible to be sure of my modification of task_executor.py, was the modification necessary ?

This comment has been minimized.

pmonsimi replied Aug 5, 2018

I'm new to contributing to open source projects. In terms of copyrights and signatures, what do I have to mention on the file file_found.py ?

@ansibot

This comment has been minimized.

Contributor

ansibot commented Aug 5, 2018

The test ansible-test sanity --test pep8 [explain] failed with 1 error:

lib/ansible/plugins/lookup/file_found.py:77:32: E225 missing whitespace around operator

The test ansible-test sanity --test yamllint [explain] failed with 1 error:

test/integration/targets/iterators/tasks/main.yml:232:3: error syntax error: expected <block end>, but found '-'

click here for bot help

@ryansb ryansb removed the needs_triage label Aug 7, 2018

@mattclay

This comment has been minimized.

Member

mattclay commented Aug 8, 2018

CI failure in integration tests:

2018-08-05 21:50:40 ERROR! Syntax Error while loading YAML.
2018-08-05 21:50:40   expected <block end>, but found '-'
2018-08-05 21:50:40 
2018-08-05 21:50:40 The error appears to have been in '/private/var/root/ansible/test/integration/targets/iterators/tasks/main.yml': line 232, column 3, but may
2018-08-05 21:50:40 be elsewhere in the file depending on the exact syntax problem.
2018-08-05 21:50:40 
2018-08-05 21:50:40 The offending line appears to be:
2018-08-05 21:50:40 
2018-08-05 21:50:40 
2018-08-05 21:50:40   - name: test file_found
2018-08-05 21:50:40   ^ here

@mattclay mattclay added the ci_verified label Aug 8, 2018

if self._task.loop_with == 'first_found':
# first_found loops are special. If the item is undefined then we want to fall through to the next value rather than failing.
if self._task.loop_with == 'first_found' or self._task.loop_with == 'file_found':
# first_found and file_found loops are special. If the item is undefined then we want to fall through to the next value rather than failing.

This comment has been minimized.

@bcoca

bcoca Aug 9, 2018

Member

lookups have a toggle now to deal with errors, this is something we want to remove, they should not be hard coded into task executor.

description: list of file names
required: True
paths:
description: list of paths in which to look for the files

This comment has been minimized.

@bcoca

bcoca Aug 9, 2018

Member

doesn't this overlap a lot with fileglob/filetree> ... just like using w/o the *

@ansibot ansibot added the stale_ci label Aug 17, 2018

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment