Ansible: Appending items to a List
Simple task to append items to a list
- name: Append items to a list
hosts: localhost
gather_facts: false
vars:
mylist: []
tasks:
- name: Append list with additional mapping
ansible.builtin.set_fact:
mylist: "{{ mylist + [{'name': 'blabla', 'mode': 1}] }}"
- name: Append list with additional mapping
ansible.builtin.set_fact:
mylist: "{{ mylist + [{'name': 'yoyoyo', 'mode': 2}] }}"
- name: Print the updated list
ansible.builtin.debug:
msg: "{{ item.name }}"
with_items:
- "{{ mylist }}"