extract sublist out of list

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

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