- hosts: localhost gather_facts: no vars: foo: [] bar: "{{ foo[0] }}" tasks: - debug: msg: "{{ bar }}" register: result ignore_errors: yes - assert: that: - '"foo[0]" in result.msg' - '"object has no element 0" in result.msg'