I just had this exact problem. Hopefully this is helpful to anyone else who comes across this thread.
An empty list is falsey, so mylist|selectattr('list') should get what you're looking for, and mylist|rejectattr('list') would return elements that have an empty list. On Tuesday, July 5, 2016 at 7:44:27 AM UTC-5, Mark Gibson wrote: > > Hi > > I'm trying to select a set of objects where an attribute (of type list) is > not empty. > > mylist: > - name: name1 > list: [] > - name: name2 > list: > - item1 > - item2 > > > There seems to be no jinja2 test (in the documentation at least) that > allows one to test on empty / notempty. > > I want to be able to do something like: > > mylist|selectattr( 'list', 'notempty' ) > > Is there a nice Ansible/Jinja2 trick that I'm missing that can do what I > want? > > Thanks > Mark > > -- 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 ansible-project+unsubscr...@googlegroups.com. To post to this group, send email to ansible-project@googlegroups.com. To view this discussion on the web visit https://groups.google.com/d/msgid/ansible-project/ed33ec2d-2164-40f7-863f-b7d0358417b7%40googlegroups.com. For more options, visit https://groups.google.com/d/optout.