ansible/test
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
..
cache
env
integration Make query with errors='ignore' return a blank list (#57038) 2019-05-29 13:23:02 -04:00
legacy Removed legacy Digital Ocean tasks (#51786) 2019-04-29 12:16:31 -04:00
results
runner Add missing scp dependency for ios_file tests (#56956) 2019-05-28 17:51:10 +05:30
sanity $result.reboot_required = $feature_result.RestartNeeded (#56419) 2019-05-28 01:21:56 -04:00
units Rename _facts -> _info (#57028) 2019-05-28 13:43:04 +02:00
utils Add Hetzner Cloud to CI integration tests. 2019-04-09 15:41:50 -07:00