# extract sublist out of list

**URL:** <https://forum.ansible.com/t/extract-sublist-out-of-list/14188>\
**Category:** Ansible Project\
**Created:** [December 20, 2013, 2:23am UTC](https://forum.ansible.com/t/extract-sublist-out-of-list/14188 "2013-12-20T02:23:31Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![Johannes\_Zillmann](https://avatars.discourse-cdn.com/v4/letter/j/58f4c7/32.png) [@Johannes\_Zillmann](https://forum.ansible.com/u/Johannes_Zillmann)\
**Post date:** [December 20, 2013, 2:23am UTC](https://forum.ansible.com/t/extract-sublist-out-of-list/14188/1 "2013-12-20T02:23:31Z")

</div>

Hey guys,

i’m having following variable object structure:

> folders:
> 
> - {folder: ‘/’, owner: “owner1”, permission: ‘775’}
> - {folder: ‘/tmp’, owner: “owner2”, permission: ‘777’}
> - {folder: ‘/test’, owner: “owner3”, permission: ‘777’}

‘folders’ is the variable i pass down to another task file.  
In that task-file, is it possible to extract a list of ‘owners’ out of the ‘folders’ variable ?  
Something like

> - name: Print owners  
> debug: “msg={{folders.folder}}”

?  
best regards  
Johannes

---

<div class="post-metadata">

**Author:** ![kahlil.hodgson](https://avatars.discourse-cdn.com/v4/letter/k/b9bd4f/32.png) [@kahlil.hodgson](https://forum.ansible.com/u/kahlil.hodgson)\
**Post date:** [December 20, 2013, 3:33am UTC](https://forum.ansible.com/t/extract-sublist-out-of-list/14188/2 "2013-12-20T03:33:40Z")

</div>

For jinja 2.6 you can do

{{ folders | join(', ', attribute='owner') }}

Is this what you are after?

There are some cool new mapping filters on the horizon with jinja 2.7,  
but I'm not sure when they will be commonly avaliable.

K

Kahlil (Kal) Hodgson GPG: C9A02289  
Head of Technology (m) +61 (0) 4 2573 0382  
DealMax Pty Ltd (w) +61 (0) 3 9008 5281

Suite 1415  
401 Docklands Drive  
Docklands VIC 3008 Australia

"All parts should go together without forcing. You must remember that  
the parts you are reassembling were disassembled by you. Therefore,  
if you can't get them together again, there must be a reason. By all  
means, do not use a hammer." -- IBM maintenance manual, 1925
