On 11.10.2019 22:23, Jason Crabtree wrote:
> Hello,
>
> I'm trying to build a list from data in other lists by looping over
> lists
> and using set_fact to build a new list.
>
> ----------------------------------------------
> - name: "test list build"
> hosts: localhost
> connection: local
> gather_facts: no
> become: no
>
>
> vars:
> location_list:
> site:
> - portland
> - miami
> - chicago
> item_list:
> - nowhere
>
>
>
> tasks:
>
> - name: "create list"
> set_fact:
> item_list: '{{ item_list + [ "{{ item }}" ] }}'
> loop: "{{ location_list.site }}"
You can't use {{ }} inside {{ }} since you are already in template mode.
So use this instead
item_list: '{{ item_list + [ item ] }}'
But you can solve this a lot faster without a loop with the union filter
- name: "create list"
set_fact:
item_list: '{{ item_list | union(location_list.site) }}'
--
Kai Stian Olstad