Populate an Ansible Fact from a loop

tasks:
  - name: Get list of elements from list_vars
    set_fact:
      my_new_list: "{{ my_new_list | default([]) | union([item]) }}"
    loop: "{{ list_vars }}"

  - name: Get list of elements from list_vars 
    set_fact:
      my_new_list: "{{ my_new_list | default([]) + [item] }}"
    loop: "{{ list_vars }}"
Previous
Next