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
--
You received this message because you are subscribed to the Google Groups "Ansible
Project" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To view this discussion on the web visit
https://groups.google.com/d/msgid/ansible-project/7cf93ac5be314fd34f85eddedd788859%40olstad.com.