Why is new_list not being concatenated too?
---
- hosts: localhost
gather_facts: False
tasks:
- name: Set init list
set_fact:
init_list:
- 1
- 2
- 3
- name: New list from with_items
set_fact:
new_list: "{{ new_list|default([]) + [ item ] }}"
with_items: "{{ init_list }}"
- debug:
var: new_list
When I run this short script I get the following output:
TASK [Set init list]
*************************************************************************
ok: [localhost]
TASK [New list from with_items]
*************************************************************************
ok: [localhost] => (item=1)
ok: [localhost] => (item=2)
ok: [localhost] => (item=3)
TASK [debug]
*************************************************************************
ok: [localhost] => {
"new_list": [
3
]
}
I am expecting new_list to contain 1,2,3. The concatenation is working but overwriting each time. I was sure this was working before (Ubuntu 16.04, unsure of Ansible version) and I am wondering if this is an Ansible version issue.
# Ubuntu 18.04
# Ansible --version
ansible 2.5.1
python version = 2.7.15rc1 (default, Nov 12 2018, 14:31:15) [GCC 7.3.0]
Note: I know there are other jinja2 filters that could potentially work around this e.g. map, list, etc, but they are not easily applicable in my production code.