Optional second key with_subelements

Hi,

I have a vars file with the following:

applications:

  • name: app1

sublist:

  • item11

  • item12

  • name: app2

sublist:

  • item21

  • item22

  • name: app3

…and a playbook task of:

  • debug: msg=“{{ item.0.name }}”

with_subelements:

  • applications

  • sublist

… which bombs out on the last application.

I was wondering if there was a more “ansible” (or python) way of having the second key optional for the with_subelements loop.

I’ve unsuccessfully tried adding a 'when: “‘ssl’ in item.0” condition.

TIA,

John

You could write your own lookup plugin.

I think it would be very important to have the existing continue to require the key, to avoid confusing errors in the case of typo’ing the key and not getting any results.