-
Notifications
You must be signed in to change notification settings - Fork 24.2k
allow 'ignore_missing' for fileglob lookups #47344
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
base: devel
Are you sure you want to change the base?
Conversation
|
Hi @philfry, thank you for submitting this pull-request! |
|
this is redundant with the 'errors' option available to all lookups. https://docs.ansible.com/ansible/latest/plugins/lookup.html#using-lookup-plugins |
The ---
- hosts: all
gather_facts: no
tasks:
- name: "with errors=strict"
debug: var=item
loop: '{{lookup("fileglob",
"files/"+inventory_hostname+"/iptables",
wantlist=true, errors="strict")}}'
- name: "with errors=ignore"
debug: var=item
loop: '{{lookup("fileglob",
"files/"+inventory_hostname+"/iptables",
wantlist=true, errors="ignore")}}'
- name: "with errors=warn"
debug: var=item
loop: '{{lookup("fileglob",
"files/"+inventory_hostname+"/iptables",
wantlist=true, errors="warn")}}'
... |
|
ah, nvmd thought you wanted to handle an error, not a warning |
e0389d0 to
5d61144
Compare
5d61144 to
f57a138
Compare
s-hertel
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@philfry You can test this with a runme.sh style test or by running ansible-playbook from within the play (you'd just need to escape variables so they're templated at the right time). I put together a test for you:
diff --git a/test/integration/targets/lookup_fileglob/non_existent/play.yml b/test/integration/targets/lookup_fileglob/non_existent/play.yml
index e92dff5acc..6733952991 100644
--- a/test/integration/targets/lookup_fileglob/non_existent/play.yml
+++ b/test/integration/targets/lookup_fileglob/non_existent/play.yml
@@ -4,3 +4,22 @@
- name: fileglob should be empty
assert:
that: q("fileglob", seed) | length == 0
+
+ - name: Test ignore_missing
+ vars:
+ query_with_warnings: "query('fileglob', 'missing/file')"
+ query_without_warnings: "query('fileglob', 'missing/file', ignore_missing=true)"
+ warning: "Unable to find 'missing' in expected paths"
+ block:
+ - name: Test a warning is given for a missing path
+ command: ansible localhost -m debug -a msg="{{ '{{' + query_with_warnings + '}}' }}"
+ register: warn_for_missing
+
+ - name: Test ignoring the warning
+ command: ansible localhost -m debug -a msg="{{ '{{' + query_without_warnings + '}}' }}"
+ register: ignore_missing
+
+ - assert:
+ that:
+ - warning in warn_for_missing.stderr
+ - warning not in ignore_missing.stderrBut while I was looking into this, I feel like a new option is redundant with the general lookup option errors which is handled in the core engine. @bcoca what do you think about adding the errors option instead, defaulting to warn for backwards compatibilty? Since fileglob is handling missing files itself and always warns, this effectively means support is missing for both errors=strict and errors=ignore and only behaves like errors=warn.
I also noticed the first_found plugin has done basically the same thing - in addition to skipping a missing file with errors=warn|ignore, it has it's own skip option, which also seems redundant to me - but adding an option with either of the existing names might be nice for consistency.
|
first_found had preexisting options, we should really pass in the errors to the file finding function and suppress warnings when apropos. |
This comment was marked as resolved.
This comment was marked as resolved.
This comment was marked as resolved.
This comment was marked as resolved.
|
The branch needs to be rebased for the CI to pick it up. |
37c616d to
88f5af8
Compare
|
/azp run |
|
Azure Pipelines successfully started running 1 pipeline(s). |
SUMMARY
There are situations where it's useful to hide the
Unable to find ... in expected paths (use -vvvvv to see paths)message. This PR adds the ability to passignore_missingto thefileglobplugin. See below for example.ISSUE TYPE
COMPONENT NAME
fileglobANSIBLE VERSION
ADDITIONAL INFORMATION
output: