I am trying to append to a list:
- name: Set found
set_fact:
found: |
{% set j2found = [ 'hi' ] %}
{%- for user in "1", "2" -%}
{% set j2found = j2found + [ user ] %}
{%- endfor %}
{{ j2found }}
- name: Show found
debug:
msg: "WHAT I FOUND: {{ item }}"
loop: "{{ found }}"
found contains only 'hi'. Why doesn't that variable get appended to? I'm doing something obvious and wrong, but I can't find it.
Thanks.
EDIT: The answers below show the preferable and simpler way to add to my list, and larsks is correct about the scope of the variable. So there's no way to do this with a set statement. But one can append to a list in jinja2 thusly:
set junk = j2found.append(user)
junk, of course, contains nothing useful and is ignored.