[Closed] It is a bug in Ansible v2.5.1, see comment below.
I want to build a new list based on a dictionary. So I try with set_fact and a loop but the variable only contains the last value (not the list)
I try simpler example without dictionary. I use this web site: https://ttl255.com/ansible-appending-to-lists-and-dictionaries/. And it doesn't work has expected.
---
- name: Append to list
hosts: localhost
vars:
devices: []
cisco:
- CiscoRouter01
- CiscoRouter02
- CiscoRouter03
- CiscoSwitch01
arista:
- AristaSwitch01
- AristaSwitch02
- AristaSwitch03
tasks:
- name: Add Cisco and Airsta devices to the list
set_fact:
devices: "{{ devices + [item] }}"
with_items:
- "{{ cisco }}"
- "{{ arista }}"
- name: Debug list
debug:
var: devices
verbosity: 0
Extract of the output:
TASK [Debug list] *********************************************************************************************************
ok: [localhost] => {
"devices": [
"AristaSwitch03"
]
}
Expected:
TASK [Debug list] *********************************************************************************************************
ok: [localhost] => {
"devices": [
"CiscoRouter01",
"CiscoRouter02",
"CiscoRouter03",
"CiscoSwitch01",
"AristaSwitch01",
"AristaSwitch02",
"AristaSwitch03"
]
}
I use the ansible version: 2.5.1