In case anyone cares, the way to do this is:

- name: x
  set_fact:
    src_from_list: "{{ files|map(attribute='src')|list }}"

- name: y
  debug: msg='{{ item }}'
  with_items: 
    - "{{ src_from_list }}"

which then outputs the values of 'src' (that being 'a', and 'b')

Thanks,
Nico

On Sunday, August 2, 2015 at 10:10:30 AM UTC+2, Nico K. wrote:
>
> Hi, 
>
> I've been restructuring my variables and ended up with something along the 
> lines of:
>
> files:
>   - { src: 'a' }
>   - { src: 'b' }
>
> and a role that does:
>
> - name: x
>   template: 
>     src: {{ item.src }}
>     ...
>     mode: {{ item.mode|default(0755) }} 
>     owner: {{ item.owner|default(root) }}
>
> This allows me to easily override the ownership/mode on a single file, yet 
> have defaults for them if not specified, it also makes a step like this 
> easily exchangeable with other roles (assuming you use the same variable 
> structure there).
> Anyway, what's problematic with such a layout is to determine whether a 
> given file exists in a list of other files (for example for the sake of 
> removing unmanaged files), think:
>
> (Please bear in mind that I'm typing this from memory, so if I mixed up 
> the syntax of a module, no need to point that out, just trying to 
> illustrate my use-case)
>
> - name: collect files..
>   shell: blah
>   register: found_files
>
> - name: remove unmanaged
>   file:
>     path: {{ item }} 
>     state: absent
>   with_items:
>     - found_files
>   when: item not in files 
>
> This is where it goes wrong, as files no longer is a flat list, but a list 
> containing a dictionary; is there an easy way to say "when: item not in 
> files.[*].src"? Or do I have to start using with_nested in this case 
> (results in quite some overhead!!).
>
> Thanks,
> Nico 
>
>

-- 
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 post to this group, send email to [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/ansible-project/2efbcc03-d030-402b-97b8-7027ae79cf31%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to