community.general/lib/ansible
Ian Wienand 39945b8570 Make query with errors='ignore' return a blank list (#57038)
The jinja2 query() function (or lookup with wantslist=True, which is
the same thing) should always return a list.

However, if you combine a query with errors='ignore' and take the
error path, the current code returns a None value.  This is important
in a case such as

 - name: Conditional include file
   import_tasks: '{{ item }}'
   vars:
     params:
       files:
         - path/file1.yaml
         - path/file2.yaml
   loop: "{{ q('first_found', params, errors='ignore') }}"

If neither file1.yaml or file2.yaml exist, this should do nothing by
returning an empty list to the loop.  Currently if you run the above
task you'll get a rather unhelpful:

 Invalid data passed to 'loop', it requires a list, got this instead: .

This change ensures that when a query ignores an error, it returns a
empty list.  The errors='ignore' case is tested in several variants
with first_found.  The extant (but deprecated) "skip: True" for
first_found doesn't seem to be explicitly tested; a test is added here
to avoid regressions before removal in 2.12.

This fixes a regression you'll hit if you follow the suggestion in the
deprecation message included with
e17a2b502d to use errors=ignore over
"skip: True" for first_found.  This change adds an example that points
out the query/lookup difference and also fixes the error message to
not mention the now deprecated "skip: True".

Closes #56775
2019-05-29 13:23:02 -04:00
..
cli fix collection adjacent loading with --playbook-dir (#56194) 2019-05-22 11:06:54 -04:00
compat Update bundled copy of selectors2 from 1.1.0 to 1.1.1 (#55457) 2019-04-23 11:52:24 -05:00
config Allow finer grained control for dupe YAML keys (#56933) 2019-05-28 11:57:16 -04:00
errors Catch sshpass authentication errors and don't retry multiple times to prevent account lockout (#50776) 2019-01-23 11:32:25 -05:00
executor Not native, but text (#55676) 2019-05-24 14:49:04 -04:00
galaxy Update galaxy cli metadata file templates (#51398) 2019-02-22 00:54:02 -05:00
inventory The InventoryData class does not have a get_vars method and InventoryManager's get_vars never appears to have been used (#56804) 2019-05-22 13:56:47 -04:00
module_utils meraki - Rewrite update requirement check (#48394) 2019-05-29 10:18:01 -04:00
modules update ospf modules to fix bugs as software version changes (#56974) 2019-05-29 12:40:30 -04:00
parsing Allow finer grained control for dupe YAML keys (#56933) 2019-05-28 11:57:16 -04:00
playbook Prevent vars premature templating (#56117) 2019-05-23 09:42:19 -04:00
plugins Make query with errors='ignore' return a blank list (#57038) 2019-05-29 13:23:02 -04:00
template Make query with errors='ignore' return a blank list (#57038) 2019-05-29 13:23:02 -04:00
utils some logging fixes (#56311) 2019-05-24 16:43:47 -04:00
vars Not native, but text (#55676) 2019-05-24 14:49:04 -04:00
__init__.py
constants.py removed previouslly deprecated settings (#55662) 2019-05-15 16:36:30 -04:00
context.py Become plugins (#50991) 2019-02-11 11:27:44 -06:00
release.py Cleanup the tree for post-2.8-branch 2019-04-12 12:57:35 -07:00