Unexpected behavior change in loop over debug task in 2.14.2 -> 2.16 upgrade

It’s best to use loop instead of with_items for looping over a list, because it involves less magic. with_items: ['foo'] is the equivalent of loop: "{{ query('items', ['foo']) }}", which is itself surprising to most people and can have surprising behaviour. The change in behaviour is due to the security fix that made it harder for data marked as unsafe to be evaluated. The result of lookups (like items) is marked as unsafe by default, so with_items transforms your list into a list of unsafe strings.

It’s also best to avoid embedded templates entirely, and more efficient to use a non-loop construct here.

  - debug:
      msg:
        rc: "{{ result.rc }}"
        stdout: "{{ result.stdout }}"
        stderr: "{{ result.stderr }}"
TASK [debug] *******************************************************************
ok: [localhost] =>
    msg:
        rc: 0
        stderr: ERROR OUTPUT
        stdout: TASK OUTPUT
2 Likes